title: Preventing N+1 queries in Rails
body: <p>I've seen a few examples of passing an <code>:include</code> hash value when calling one of ActiveRecord's <code>find</code> methods in Rails. However, I haven't seen any examples of whether this is possible via relationship methods.  For example, let's say I have the following:</p>
  
  <pre><code>def User &lt; ActiveRecord::Base
    has_many :user_favorites
    has_many :favorites, :through =&gt; :user_favorites
  end
  
  def Favorite &lt; ActiveRecord::Base
    has_many :user_favorites
    has_many :users, :through =&gt; :user_favorites
  end
  
  def UserFavorite &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :favorite
  end
  </code></pre>
  
  <p>All the examples I see show code like this:</p>
  
  <pre><code>User.find(:all, :include =&gt; :favorite)
  </code></pre>
  
  <p>But I don't see any examples showing the use of relationships.  Would it instead be possible for me to do something like this?</p>
  
  <pre><code>User.favorites(:include =&gt; :user)
  </code></pre>