我的关联选项似乎未得到遵守。
class ClassRoom < ActiveRecord::Base
  has_many :class_assignments, :dependent => :destroy
  has_many :people, :through=>:class_assignments
class Person < ActiveRecord::Base
  has_many :class_assignments, :dependent => :destroy
  has_many :class_rooms, :through=>:class_assignments
class ClassAssignment < ActiveRecord::Base
  belongs_to :person
  belongs_to :class_room也就是说,当一个人或一个教室被删除时,连接表/模型中的记录也应该被删除。
但是,ClassRoom.last.destroy会销毁ClassRoom,但不会销毁任何与之相关的ClassAssignments。
我知道在使用:through时:dependent=>:destroy会被忽略,但我应该能够在join模型上使用它,对吗?
发布于 2010-08-06 03:26:17
试一试
  class ClassRoom < ActiveRecord::Base 
  def before_destroy
    self.class_assignments.destroy_all
  endperson也是如此
https://stackoverflow.com/questions/3411316
复制相似问题