How do I use the hash :condition on a .find for a nil? method in Rails (has_one relationship) -


I want to find all those contacts where their value is related to: is not the value of contact_status (this means

I created a alias_attribute: status,: status_contact

: Can I do something with:

  Contacts = contact.find (: all :: conditions = & gt; {: contact_status = & gt; nil} ,: include = & gt; {status_contact})  

I do not Am sure how zero actually works, I do not give any value for it, this head Ph: One is: has_one relationships.

Edit: It seems like a contact that relations should have a relationship in order to make changes with comments, it seems that in fact, There is a relation - which is 'the_one' with respect to the status_ contact.

I am using Searchlogic to designate a snap ... I looks this Does the problem solve, anybody familiar with that?

However, there are times when Yogkrta can assign that value. I do not want them to come in this search.

Get this error at present:

SQLite3 :: SQLException: Pass ".": Syntax Error: Select "Contact" "ID" AS T_R 0, "Contact ". "First_name" as t r_r 1, "contact". "Last_name" as t r_r2, "contact". "Title" AS T-RR3, "Contact". "Phone" AS T-R4, "Contact" "Fax" AS T-R5, "Contact" AS T R_6, "Contact". "Company" AS T RR 7, "Contact". "Created" AS T. _ R8, "Contact". "UpdatedTat" AS T-R9, "Contact" "Contact_id" AS T R_ 10, "Contacts" AS T0_R11, "Contacts". "COMPANY_ID" AS T-12R, "CONTACTS". "Address_ID" AS T-0_R13, "Contact" "VCard_file_name" AS T0_R14, "Contact" Vcard_content_type "AS t0_r15", "Contact". "Vcard_file_size" AS t0_r16, "Contact". "Vcar d_updated_at" AS t0_r17, "Contact". "Direct" AS t0_r18, "Contact" "Chinese" AS t0_r19, "status_contacts". "ID" AS T1_R0, "Status", "Status" AS T1_R1, "Status_Cactact", "Contact_ID" AS T1_R2, "Status_Cancon TAS". "Made_at "AS T1_R3," status_contact ". Go to status_contacts.contact_id = contacts.id (" status_contact ") on" Contacts "LEFT OUTER" status_contacts "from" updatedTight "AS T1_R4FOR .status = NULL)

Your error does not correspond to the code you are displaying You are doing something like that

 : conditions => ['position =?', Zero]  

but what you should check is < Code> status , which is a linked object such that you will check it in Ruby-code, but not in SQL.

Within your table, you will see the status_contact_id There will be an area called , and when that x

Code> contact = contact.find (: All ,: conditions = & gt; "Status_contact_id IS NULL")

[edit] Since you are using the has_one relationship, read it completely, the foreign key is actually It is defined in the status_contacts table, but to make the items which do not occur any condition becomes a little more complicated.

In SQL, you can do something like

  * from contacts where there is no ID (choose from Contact_id status_contacts)  
< P> And I will translate this in Ruby like this:

  contact = contacts.find_by_sql ("Select from contacts' where id is not individually I can not think in a better way now .    (choose contact_id from status_contact) " 


Comments