例如,我有三個型號的用戶,問題和答案,以及它們之間的關係是: class User < ActiveRecord::Base
has_many :answers
has_many :questions
end
class Question < ActiveRecord::Base
has_many :answers, :dependent => :destroy
在Ruby on Rails 4中,假設父母有很多孩子。當父母被刪除時,孩子也必須被刪除。除此之外,兒童不得被刪除,除非是孤兒。怎麼做? 我試着用以下 class Parent < ActiveRecord::Base
has_many :children, inverse_of: :parent, dependent: :destroy
end
class Child < Act
在ActiveRecord模型中安裝圓形dependent: :destroy選項是否安全? class Student < ActiveRecord::Base
has_one :user, dependent: :destroy
end
class User < ActiveRecord::Base
belongs_to :student, dependent: :de