简体   繁体   English

Rails和Searchlogic:使用searchlogic条件查找与所有给定产品类别匹配的产品

[英]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. 我的Rails应用程序中有一个模型出版物和一个模型类别。 Both are connected with a has_and_belongs_to_many association. 两者都通过has_and_belongs_to_many关联进行连接。

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. 我想在多个select_box中指定类别。

Publication.released.categories_id_is([1,2]) is not working because the categories are connected with OR. Publication.released.categories_id_is([1,2])不起作用,因为类别与OR关联。

With Publication.categories_id_is_all([1,2]) the categories are connected with AND, but no result is given back. 使用Publication.categories_id_is_all([1,2]) ,类别通过AND连接,但未返回结果。

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. 查看日志以查看那些命令实际上正在运行什么SQL查询。

You may want to try 您可能要尝试

Publication.categories_id_equals_all([1,2])

As the is shortcut could be causing a problem there 由于is捷径可能会引起问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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