title: How to fetch data through "has_many" associations?
body: <p>I have the following structure of models:</p>
  
  <pre><code>class User &lt; ActiveRecord::Base
    has_many :favorites
  end
  class Favorite &lt; ActiveRecord::Base
    belongs_to :user
    belongs_to :company
  end
  class Color &lt; ActiveRecord::Base
    belongs_to :company
  end
  class Company &lt; ActiveRecord::Base
    has_many :colors
    has_many :favorities
  end
  </code></pre>
  
  <p>It means that a company has many colors. Every user can favorite a company (and I can print out then every color that the respective company offers).</p>
  
  <p>But I am trying to display all colors that companies I've favorited offers.</p>
  
  <p>I've tried it something like this:</p>
  
  <pre><code>favorited_colors = current_user.favorites.colors
  
  undefined method `colors' for #&lt;ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_Favorite:0x007fe037da01f0&gt;
  </code></pre>
  
  <p>and </p>
  
  <pre><code>favorited_colors = current_user.favorites.companies.colors
  
  undefined method `companies' for #&lt;ActiveRecord::Associations::CollectionProxy::ActiveRecord_Associations_CollectionProxy_Favorite:0x007fe038ce8db0&gt;
  </code></pre>
  
  <p>Is there any other way how to get a list of all colors from favorited companies than to iterated via <strong>each</strong> loops through all favorited companies and save all colors into an array?</p>
  
  <p>Thank you</p>