У меня есть приложение rails am building. Он состоит из центров и студентов. Центр имеет различные дни, когда он находится в сеансе. Студент относится к центру и выбирает дни, когда они будут посещать дни активного центра. У меня есть настройка ассоциации, как показано ниже. Уничтожение CenterDay не приводит к уничтожению StudentDay.Уничтожить связанные объекты в приложении для рельсов
Пожалуйста, помогите
class Center < ActiveRecord::Base
has_many :center_days, :dependent => :destroy
has_many :school_days, :through => :center_days
accepts_nested_attributes_for :school_days
end
class Student < ActiveRecord::Base
belongs_to :center
has_many :student_days, :dependent => :destroy
has_many :center_days, :through => :student_days
accepts_nested_attributes_for :center_days
end
class SchoolDay < ActiveRecord::Base
has_many :center_days
has_many :centers, :through => :center_days
end
class CenterDay < ActiveRecord::Base
belongs_to :center
belongs_to :school_day
has_many :student_days, :dependent => :destroy
has_many :students, :through => :student_days
end
class StudentDay < ActiveRecord::Base
belongs_to :student
belongs_to :center_day
end
CenterDay разрушается при обновлении или уничтожить центр, а не напрямую, как вы выразились. Или есть способ уничтожить его непосредственно при обновлении или уничтожении центра? –