title: ActiveRecord .missing - Why doesnt this work?
body: <p>Working on Rails 6.1</p>
  <p>I've got this base class:</p>
  <pre><code>class Post &lt; ApplicationRecord
  end
  </code></pre>
  <p>And these two subclasses representing a face-to-face lesson and it's live transmission:</p>
  <pre><code>class Live &lt; Post
    belongs_to :in_person_live,
               foreign_key: :live_of_in_person_live_id,
               class_name: 'InPersonLive',
               required: false,
               inverse_of: :online_live,
               touch: true
  end
  
  class InPersonLive &lt; Post
    has_one :online_live,
            class_name: 'Live',
            foreign_key: 'live_of_in_person_live_id',
            inverse_of: :in_person_live,
            touch: true
  end
  </code></pre>
  <p><strong>I'd like to query for face-to-face lessons without a live transmission.</strong></p>
  <p>I came up with this, which seems to work:</p>
  <pre><code>InPersonLive.where.not(id: Live.where.not(live_of_in_person_live_id: nil).select(:live_of_in_person_live_id)).count 
  </code></pre>
  <p>But was wondering why this doesnt work:</p>
  <pre><code>InPersonLive.where.missing(:online_live).count 
  </code></pre>
  <p>I'd expect the <code>.missing</code> to return the same result but it always returns 0.</p>
  <p>The generated SQL is different in both cases but again I don't understand why the result is different, seems to me like they should return the same set.</p>
  <p><code>InPersonLive.where.not(id: Live.where.not(live_of_in_person_live_id: nil)).count</code> generates:</p>
  <pre><code>SELECT COUNT(*) FROM &quot;posts&quot; WHERE &quot;posts&quot;.&quot;type&quot; = $1 AND &quot;posts&quot;.&quot;id&quot; NOT IN (SELECT &quot;posts&quot;.&quot;live_of_in_person_live_id&quot; FROM &quot;posts&quot; WHERE &quot;posts&quot;.&quot;type&quot; = $2 AND &quot;posts&quot;.&quot;live_of_in_person_live_id&quot; IS NOT NULL)  [[&quot;type&quot;, &quot;InPersonLive&quot;], [&quot;type&quot;, &quot;Live&quot;]]
  </code></pre>
  <p>while <code>InPersonLive.where.missing(:online_live).count</code> generates:</p>
  <pre><code>SELECT COUNT(*) FROM &quot;posts&quot; LEFT OUTER JOIN &quot;posts&quot; &quot;online_lives_posts&quot; ON &quot;online_lives_posts&quot;.&quot;live_of_in_person_live_id&quot; = &quot;posts&quot;.&quot;id&quot; AND &quot;online_lives_posts&quot;.&quot;type&quot; = $1 WHERE &quot;posts&quot;.&quot;type&quot; = $2 AND &quot;posts&quot;.&quot;id&quot; IS NULL  [[&quot;type&quot;, &quot;Live&quot;], [&quot;type&quot;, &quot;InPersonLive&quot;]]
  </code></pre>