Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I use the hash :condition on a .find for a nil? method in Rails (has_one relationship)
    text
    copied!<p>I want to find all Contacts where the value of their :has_one relationship to :contact_status does not have a value (does that mean nil?)</p> <p>I created an <code>alias_attribute :status, :status_contact</code></p> <p>Can I do something along the lines of:</p> <pre><code>contacts = Contact.find(:all, :conditions =&gt; {:contact_status =&gt; nil }, :include =&gt; {:status_contact} ) </code></pre> <p>I'm not sure exactly how nil works. Basically, I don't assign any value to it, it is just a :has_one relationship.</p> <p><strong>EDIT: Sounds like contacts should be a belongs_to relationship so making change</strong> From the comments, it sounds like Contacts should actually have a belongs_to relationship to status_contacts which in turn 'has_one' with Contacts.</p> <p>I am using Searchlogic to create named_scopes...I <em>think</em> it solves the problem, anyone familiar with that?</p> <p>However, there are times the user can assign a value to that. I don't want those to come up in the find.</p> <p>Currently get this error:</p> <p>SQLite3::SQLException: near ".": syntax error: SELECT "contacts"."id" AS t0_r0, "contacts"."first_name" AS t0_r1, "contacts"."last_name" AS t0_r2, "contacts"."title" AS t0_r3, "contacts"."phone" AS t0_r4, "contacts "."fax" AS t0_r5, "contacts"."email" AS t0_r6, "contacts"."company" AS t0_r7, "contacts"."created_at" AS t0 _r8, "contacts"."updated_at" AS t0_r9, "contacts"."campaign_id" AS t0_r10, "contacts"."date_entered" AS t0_ r11, "contacts"."company_id" AS t0_r12, "contacts"."address_id" AS t0_r13, "contacts"."vcard_file_name" AS t0_r14, "contacts"."vcard_content_type" AS t0_r15, "contacts"."vcard_file_size" AS t0_r16, "contacts"."vcar d_updated_at" AS t0_r17, "contacts"."direct" AS t0_r18, "contacts"."sugarcrm" AS t0_r19, "status_contacts". "id" AS t1_r0, "status_contacts"."status" AS t1_r1, "status_contacts"."contact_id" AS t1_r2, "status_contac ts"."created_at" AS t1_r3, "status_contacts"."updated_at" AS t1_r4 FROM "contacts" LEFT OUTER JOIN "status _contacts" ON status_contacts.contact_id = contacts.id WHERE (:status_contact.status = NULL)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload