当存在关联模型时,已知在两个模型中指定关联都会创建循环依赖关系,并导致“堆栈级别太深”错误。那么指定关系的正确位置是什么?请看看这些简单的关联:具有关联模型的工厂
class Patient
has_many :doctors, :through => :join_model
end
class Doctor
has_many :patients, :through => :join_model
end
也
class User
has_many :posts
end
class Post
belongs_to :user
end
在工厂对这些模型中,哪一个是持有协会的权利的地方吗?
这两个例子有什么共同点?我不明白... – phoet 2012-08-06 11:14:28
@phoet:两个例子都有关联。一个与“有很多通过”,另一个与“has_many”。我的问题是,如果您为每个示例创建工厂,那么哪个工厂将是指定关系的正确位置? – Emil 2012-08-06 11:20:03