[英]How do I use searchlogic to search on a belongs_to association?
Contact belongs_to status_contacts 联系人归属到状态_联系人
I only want those Contacts where no value has been assigned. 我只希望未分配任何值的那些联系人。
I installed the searchlogic plugin. 我安装了searchlogic插件。
I tried: 我试过了:
contacts = Contact.status_contact_null
And got an error. 并得到一个错误。
How can I get a full sense of how to use associations with searchlogic, and how can I use it for this particular search? 如何全面了解如何与searchlogic一起使用关联,以及如何将其用于特定搜索?
Contact.status_contact_id_is(nil)
should generate SQL that looks like this: 应该生成如下所示的SQL:
SELECT * FROM `contacts` WHERE (contacts.status_contact_id IS NULL)
Searchlogic substitutes Ruby's nil
for SQL's null
. Searchlogic将Ruby的
nil
替换为SQL的null
。
You can do the reverse with ne
(not equal) 您可以使用
ne
(不等于)进行相反的操作
Contact.status_contact_id_ne(nil)
There are a bunch of good examples on the github page for Searchlogic github页面上有大量关于Searchlogic的好例子
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.