has_and_belongs_to_many vs has_many through

前端 未结 6 1434
没有蜡笔的小新
没有蜡笔的小新 2020-11-28 03:47

Please explain the difference between has_and_belongs_to_many and has_many through relationship. When and where to use which one?

6条回答
  •  星月不相逢
    2020-11-28 04:12

    You should use has_many :through if you need validations, callbacks, or extra attributes on the join model.

提交回复
热议问题