views:

225

answers:

1

I have a model Publication and a model Category in my Rails app. Both are connected with a has_and_belongs_to_many association.

Now I would like to search publications that match one or more categories. If more than one category is given they have all assigned to the publication. I want to specify the categories in a multiple select_box.

Publication.released.categories_id_is([1,2]) is not working because the categories are connected with OR.

With Publication.categories_id_is_all([1,2]) the categories are connected with AND, but no result is given back.

Any idea's on that? Am I mising the right point in the docs. Thanks for your very welcome help!

A: 

Take a look at the logs to see what SQL query is actually being run for those commands.

You may want to try

Publication.categories_id_equals_all([1,2])

As the is shortcut could be causing a problem there

Lummo
I should also note that I've used 'equals_any' with searchlogic before and it has worked as expected but I have not tested 'equals_all' personally
Lummo