title: Rails: is it possible to add extra attribute to a has_and_belongs_to_many association?
body: <p>What I mean is if I have two models, connected by a has_and_belongs_to_many association, can I store other data in the join table for each association? That is, the extra data would not be part of a single record in either table, but instead of the connection between them. </p>
  
  <p>My actual models are as follows:</p>
  
  <pre><code>class Part &lt; ActiveRecord::Base
    has_and_belongs_to_many :assemblies
    has_and_belongs_to_many :packages
    belongs_to :user
  
    validates :name, :user_id, :presence =&gt; true
  end
  
  class Package &lt; ActiveRecord::Base
    has_and_belongs_to_many :parts
    belongs_to :user
  end
  </code></pre>
  
  <p>So the point is that each part is available in many packages, and each package has different parts. What I want to add is a quantity. That would not be quantity of each part, but of each package of each part.</p>
  
  <p>I can't find how to do this in ActiveRecord. If I was not using rails/activerecord, I'd just add a quantity column to the join table which relates parts to packages. I could obviously make this change in a migration, but how would I access the value using ActiveRecord? </p>