简体   繁体   English

我如何使用searchlogic来搜索一个Emirates_to关联?

[英]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.

相关问题 我如何为belongs_to 关联播种? - How do I seed a belongs_to association? 所属协会-我怎么称呼它? - belongs_to association — how do I call it? 如何搜索belongs_to关联属性 - How to search belongs_to association attributes 如何在没有直接belongs_to的情况下设置一种“belongs_to:through”关联? - How do I set up a kind of “belongs_to :through” association without a direct belongs_to? 在Rails 4中使用belongs_to关联 - Use belongs_to association in Rails 4 如何在Rails中将表单选择输入用于多态的Emirates_to关联? - How do you use a form select input for a polymorphic belongs_to association in Rails? 我是否需要检查 Rails 中的belongs_to 关联中是否存在记录? - Do I need to check if record exist in a belongs_to association in Rails? 在Rails 5.1 中,如何为has_many 和belongs_to 关联编写finder 方法? - In Rails 5.1, how do I write a finder method for a has_many and then belongs_to association? 如何在不更改原始类的情况下替换belongs_to关联 - How do I replace a belongs_to association without changing the original class 如何在Rails 4.2中创建一个名为has_many和belongs_to的关联? - How do I create a named has_many and belongs_to association in Rails 4.2?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM