title: Rails create object has_many through
body: <p>My models</p>
  
  <pre><code>class Collection &lt; ActiveRecord::Base
    has_many :outfits
    has_many :products, through: :outfits
  end
  
  class Outfit &lt; ActiveRecord::Base 
    belongs_to :product
    belongs_to :collection
  end
  
  class Product &lt; ActiveRecord::Base
    has_many :outfits
    has_many :collections, through: :outfits
  end
  </code></pre>
  
  <p>I want to save product in collection  model</p>
  
  <p>so one collection can have few product in it</p>
  
  <p>How can i do it? i'm a bit struggle with it</p>
  
  <p>it have tried something like this </p>
  
  <pre><code>p = Product.find_by_code('0339').id
  
  p.collections.create(product_id:p1)
  </code></pre>
  
  <p>but i guess i'm wrong</p>