title: How to get attributes from table that joins of HABTM
body: <p>I models are</p>
  
  <pre class="lang-rb prettyprint-override"><code>class User &lt; ApplicationRecord
    has_many :recipients
    has_many :notifications, through: :recipients
  end
  
  class Recipient &lt; ApplicationRecord
    belongs_to :user
    belongs_to :notification
  end
  
  class Notification &lt; ApplicationRecord
    has_many :recipients
  
    scope :unread, -&gt; { ??? }
  
    def read?
      # ???
    end
  end
  </code></pre>
  
  <p>I've page with list of notifications, that are received using: <code>@user.notifications</code>. But I need to detect which notifications aren't read yet. For this I have join table <code>recipients</code> which has field <code>read_at</code>.</p>
  
  <h2>Question</h2>
  
  <p>I want to get unread notifications like that</p>
  
  <pre class="lang-rb prettyprint-override"><code>user.notifications.unread
  </code></pre>
  
  <p>and check that specified notification isn't read</p>
  
  <pre class="lang-rb prettyprint-override"><code>user.notifications.each { |n| n.read? }
  </code></pre>
  
  <p>In first case I want to get query</p>
  
  <pre><code>SELECT "notifications".*
  FROM "notifications"
    INNER JOIN "recipients" ON "notifications"."id" = "recipients"."notification_id"
  WHERE "recipients"."user_id" = $1
    AND "recipients"."read_at" IS NOT NULL
  </code></pre>
  
  <p>In the second, I would like to avoid additional queries.</p>
  
  <p>Is it possible?</p>