title: How do rails association methods work?
body: <p>How do rails association methods work? Lets consider this example</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
     has_many :articles
  end
  
  class Article &lt; ActiveRecord::Base
     belongs_to :user
  end
  </code></pre>
  
  <p>Now I can do something like</p>
  
  <pre><code>@user = User.find(:first)
  @user.articles
  </code></pre>
  
  <p>This fetches me articles belonging to that user. So far so good.</p>
  
  <p>Now further I can go ahead and do a find on these articles with some conditions.</p>
  
  <pre><code>@user.articles.find(:all, :conditions =&gt; {:sector_id =&gt; 3})
  </code></pre>
  
  <p>Or simply declare and associations method like</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
     has_many :articles do
       def of_sector(sector_id)
         find(:all, :conditions =&gt; {:sector_id =&gt; sector_id})
       end
     end
  end
  </code></pre>
  
  <p>And do</p>
  
  <pre><code>@user.articles.of_sector(3)
  </code></pre>
  
  <p>Now my question is, how does this <code>find</code> work on the array of <code>ActiveRecord</code> objects fetched using the association method? Because if we implement our own <code>User</code> instance method called <code>articles</code> and write our own implementation that gives us the exact same results as that of the association method, the find on the fetch array of <code>ActiveRecord</code> objects wont work.</p>
  
  <p>My guess is that the association methods attach certain properties to the array of fetched objects that enables further querying using <code>find</code> and other <code>ActiveRecord</code> methods. What is the sequence of code execution in this this case? How could I validate this?</p>