我们有三堂课
class a
has_many :b
has_many :c, through: b
end
class b
belongs_to :a
belongs_to :b
end
class c
has_many :b
has_many :a, through: :b
validates_uniqueness_of :name
end
如果尝试创建类c
的实例时,如果数据库中某些类name
的2个对象以相同的a
值存在于数据库中,我很惊讶地看到对类c
的验证正在运行!为什么我根本不应该触摸类c
行时运行验证?
class B
如何属于class B
?
[class B
应该属于class C
至class A
的has_many :c, through: b
class C
也要具有has_many :a, through: :b
,反之亦然。