public
Description: Natural-looking Finder Queries for ActiveRecord
Homepage: http://www.thoughtbot.com/projects/squirrel
Clone URL: git://github.com/thoughtbot/squirrel.git
Added ability to compare to other columns.
jyurek (author)
Wed Jun 25 11:20:06 -0700 2008
commit  64e78106dee656103cf3db8f17eeb8b399b31a08
tree    7d490b3c43a3557702bc63af23fef4831eeb2a78
parent  6dcc2e35314310facd03fb955e2b2ef6f36c9ae6
...
488
489
490
491
492
 
 
493
494
495
 
 
496
497
 
498
499
500
501
502
 
 
 
 
 
 
 
 
 
 
 
503
504
505
506
507
508
...
488
489
490
 
 
491
492
493
 
 
494
495
496
 
497
498
 
 
 
 
499
500
501
502
503
504
505
506
507
508
509
510
 
 
511
512
513
0
@@ -488,21 +488,26 @@ module Squirrel
0
         
0
         op, arg_format, values = operator, "?", [operand]
0
         op, arg_format, values = case operator
0
- when :<=> then [ "BETWEEN", "? AND ?", [ operand.first, operand.last ] ]
0
- when :=~ then
0
+ when :<=> then [ "BETWEEN", "? AND ?", [ operand.first, operand.last ] ]
0
+ when :=~ then
0
           case operand
0
- when String then [ "LIKE", arg_format, values ]
0
- when Regexp then [ "REGEXP", arg_format, values.map(&:source) ]
0
+ when String then [ "LIKE", arg_format, values ]
0
+ when Regexp then [ "REGEXP", arg_format, values.map(&:source) ]
0
           end
0
- when :==, :=== then
0
+ when :==, :=== then
0
           case operand
0
- when Array then [ "IN", "(?)", values ]
0
- when Range then [ "IN", "(?)", values ]
0
- when nil then [ "IS", "NULL", [] ]
0
- else [ "=", arg_format, values ]
0
+ when Array then [ "IN", "(?)", values ]
0
+ when Range then [ "IN", "(?)", values ]
0
+ when Condition then [ "=", operand.full_name, [] ]
0
+ when nil then [ "IS", "NULL", [] ]
0
+ else [ "=", arg_format, values ]
0
+ end
0
+ when :contains then [ "LIKE", arg_format, values.map{|v| "%#{v}%" } ]
0
+ else
0
+ case operand
0
+ when Condition then [ op, oprand.full_name, [] ]
0
+ else [ op, arg_format, values ]
0
           end
0
- when :contains then [ "LIKE", arg_format, values.map{|v| "%#{v}%" } ]
0
- else [ op, arg_format, values ]
0
         end    
0
         sql = "#{full_name} #{op} #{arg_format}"
0
         sql = "NOT (#{sql})" if @negative
...
282
283
284
 
 
 
 
 
285
...
282
283
284
285
286
287
288
289
290
0
@@ -282,4 +282,9 @@ class SquirrelTest < Test::Unit::TestCase
0
     assert_equal(User.find(1),
0
                  User.scoped{ name =~ "Jon%" }.scoped{ id < 3 }.first)
0
   end
0
+
0
+ def test_conditions_can_be_rvalues
0
+ query = User.find(:query){ posts.body == posts.tags.name }
0
+ assert_equal ["((posts.body = tags.name))"], query.to_find_conditions
0
+ end
0
 end

Comments

    No one has commented yet.