Rails: is it possible to add extra attribute to a has_and_belongs_to_many association?

后端 未结 3 747
自闭症患者
自闭症患者 2021-02-04 02:37

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 w

3条回答
  •  旧巷少年郎
    2021-02-04 03:09

    There is a key difference between has_many :through and has_and_belongs_to_many the Rails guide explains the differences between the two options in greater detail, however if you want to add data that describes the relationship then use has_many :through and you can access the model that joins the two.

    This is what has_many :through looks like: Credit to the Rails guide.

提交回复
热议问题