diff --git a/lib/squeel/dsl.rb b/lib/squeel/dsl.rb index 6b41eea..1137861 100644 --- a/lib/squeel/dsl.rb +++ b/lib/squeel/dsl.rb @@ -86,7 +86,7 @@ def _(expr) # @param [Symbol, Nodes::Stub] name The name of the sifter defined in the model. # @return [Nodes::Sifter] The sifter node def sift(name, *args) - Nodes::Sifter.new name.to_sym, args + Nodes::Grouping.new(Nodes::Sifter.new(name.to_sym, args)) end # Node generation inside DSL blocks. diff --git a/lib/squeel/nodes/key_path.rb b/lib/squeel/nodes/key_path.rb index ea5c813..a543308 100644 --- a/lib/squeel/nodes/key_path.rb +++ b/lib/squeel/nodes/key_path.rb @@ -125,7 +125,7 @@ def op(operator, other) def sift(name, *args) if Stub === endpoint || Join === endpoint @path << Sifter.new(name, args) - self + Grouping.new(self) else no_method_error :sift end diff --git a/lib/squeel/nodes/stub.rb b/lib/squeel/nodes/stub.rb index fd3f38c..d2fa470 100644 --- a/lib/squeel/nodes/stub.rb +++ b/lib/squeel/nodes/stub.rb @@ -108,7 +108,7 @@ def inner # Create a keypath with a sifter as its endpoint # @return [KeyPath] The new KeyPath def sift(name, *args) - KeyPath.new([self, Sifter.new(name, args)]) + Grouping.new(KeyPath.new([self, Sifter.new(name, args)])) end # Create an outer Join node for the association named by this Stub diff --git a/lib/squeel/visitors/visitor.rb b/lib/squeel/visitors/visitor.rb index e44cdf4..f7cdb3a 100644 --- a/lib/squeel/visitors/visitor.rb +++ b/lib/squeel/visitors/visitor.rb @@ -362,6 +362,10 @@ def visit_Squeel_Nodes_Operation(o, parent) op end + def visit_Squeel_Nodes_Sifter(o, parent) + visit(context.base.active_record.send("sifter_#{o.name}", *o.args), parent) + end + # Visit an Active Record Relation, returning an Arel::SelectManager # @param [ActiveRecord::Relation] o The Relation to visit # @param parent The parent object in the context