activerecord-hackery/squeel — pull request #296 by odedniv (2013-12-02 10:20:28+00:00)
Title: wrap Nodes::Sifter with Nodes::Grouping for operators

Operators don't work on sifters, so you always have to wrap them like so: `_(sift(:my_sifter))`.
This is a patch I made that always returns the Sifter object wrapped withing Grouping.

Given the following model:
```ruby
class User < ActiveRecord::Base
sifter(:my_sifter) { id + 5 }
end
```

Here is some examples of the results before the patch:
```ruby
User.where{sift(:my_sifter) > 5}.to_sql
=> "NoMethodError: undefined method `>' for #"
User.select{sift(:my_sifter).as(column)}.to_sql
=> "NoMethodError: undefined method `as' for #"
Account.joins(:user).where{user.sift(:my_sifter) > 2}.to_sql
=> "NoMethodError: undefined method `>' for #"
```

Examples after the patch (and the expected result for the above examples):
```ruby
User.where{sift(:my_sifter) > 5}.to_sql
=> "SELECT `users`.* FROM `users` WHERE (`users`.`id` + 5) > 5"
User.select{sift(:my_sifter).as(column)}.to_sql
=> "SELECT (`users`.`id` + 5) AS column FROM `users` "
Account.joins(:user).where{user.sift(:my_sifter) > 2}.to_sql
=> "SELECT `accounts`.* FROM `accounts` INNER JOIN `users` ON `users`.`id` = `accounts`.`user_id` WHERE (`users`.`id` + 5) > 2"
```