title: Rails: Query nil has_one association
body: <p>I have two models: <code>Patient</code> and <code>CodeStatus</code>.</p>
  
  <p>CodeStatus <code>belongs_to</code> Patient, and Patient <code>has_one</code> CodeStatus</p>
  
  <p>I am trying to query all patients where <code>patient.code_status</code> is nil. I was surprised to find that <code>Patient.where(code_status: nil)</code> does not work throwing: <code>column patients.patient_id does not exist</code></p>
  
  <p>I have already found <a href="https://stackoverflow.com/questions/12515268/finding-nil-has-one-associations-in-where-query">this (fairly old) answer</a>, but I find it difficult to believe that the best way to query this is via a long string of raw SQL. I would think that rails would include this helper like they do for many other associations. Does anyone know of a less verbose solution to this? Thanks in advance. </p>