简体   繁体   中英

Rails and Searchlogic: finding products that matching all given product categories by using searchlogic condition

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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM