24
loading...
This website collects cookies to deliver better user experience
dependent: :destroy
option on some of my models' associations.class Panel < ActiveRecord::Base
belongs_to :event
has_many :panel_panelists, dependent: :destroy
has_many :panelists, through: :panel_panelists
has_many :panel_sponsors, dependent: :destroy
has_many :sponsors, through: :panel_sponsors
end
Panel
class as an example. A panel belongs to an event, and has many panelists and sponsors through linking models. When a panel is deleted, the panelists and sponsors should remain, since they can be associated with many panels. The linking records, panel_panelists
and panel_sponsors
are unique to the panel being deleted. With dependent: :destroy
, those records are deleted along with the panel.