简体   繁体   中英

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.

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?

Contact.status_contact_id_is(nil)

should generate SQL that looks like this:

SELECT * FROM `contacts` WHERE (contacts.status_contact_id IS NULL)

Searchlogic substitutes Ruby's nil for SQL's null .

You can do the reverse with ne (not equal)

Contact.status_contact_id_ne(nil)

There are a bunch of good examples on the github page for Searchlogic

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