squirrel and acts_as_rails

I have been using Squirrel (Companies like yours create meaningful solutions with thoughtbot) for performing rails searches. It really takes the thinking out of sql conditions and makes it so much more like normal ruby syntax.

I have recently been using the acts_as_tree gem(http://github.com/ jcnetdev/acts_as_tree/tree/master) for a Group model that has children, grandchildren etc. Squirrel works well for the children and parent methods since these are normal associations but for methods like "ancestors" and "all_children" which are recursive methods , squirrel won't work.

I don't fully understand how squirrel uses associations. Can you think of a way that squirrel could be used in this kind of way

Group.find(:all) do   ancestors.name.contains?("Department") end

Many thanks

Anthony

I think you've answered your own question, the 'ancestors' method is a method which returns a list, it needs an instance to work upon. Squirrel cannot supply the instance, since squirrel is tryimng to map Ruby code into a static SQL query to then find the instances.

Not a terribly clear explanation, unfortunately.

To slightly restate your problem: you're looking for the children of any Groups with name == "Department"

So the untested code

Group.find(:all) do   name == "Department" end.map{ |group| group.children }.flatten.uniq

might work. It's not a single SQL query but may be enough to get the job done.

Allan