title: Refactoring has_many with scopes
body: <p>I'm a newbie and I just showed my code to an expert, that told me I shouldn't use <code>has_many</code> to filter my variables, but <code>scopes</code>.</p>
  
  <p>I have three models : User, Product and Ownership.</p>
  
  <p>So here is my code in <strong>app/models/user.rb</strong> :</p>
  
  
  
  <pre class="lang-rb prettyprint-override"><code>class User
    has_many :ownerships, foreign_key: "offerer_id",
                           dependent: :destroy
    has_many :owned_products, through: :ownerships,
                               source: :product
    has_many :future_ownerships, -&gt; { where owning_date: nil, giving_date: nil },
                                 class_name: "Ownership",
                                 foreign_key: "offerer_id"
    has_many :wanted_products, through: :future_ownerships,
                               source: :product
  end
  </code></pre>
  
  <p>So I deleted the <code>has_many :future_ownerships</code> and <code>has_many :wanted_products</code>, and created a scope in <strong>app/models/ownership.rb</strong> :</p>
  
  <pre class="lang-rb prettyprint-override"><code>class Ownership
    scope :future, -&gt; { where owning_date: nil, giving_date: nil }
  end
  </code></pre>
  
  <p>Now I can find the future ownerships doing this : <code>user.ownerships.future</code>. But what I don't know, is how to retrieve the wanted products ? How can I make a scope in my <strong>app/models/product.rb</strong> to be able to type something like that :</p>
  
  <pre class="lang-rb prettyprint-override"><code>user.owned_products.wanted
  </code></pre>