出现跟随错误 ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection in ProjectController#create
无法修改关联“ProjectMaster#tag_masters”,因为源反射类“TagMaster”通过 :has_many 关联到“ProjectTag”。
以下是我的模型。
class ProjectTag < ActiveRecord::Base
has_many :tag_masters
has_many :project_masters
end
class TagMaster < ActiveRecord::Base
has_many :project_tags
has_many :project_masters, :through => :project_tags
end
class ProjectMaster < ActiveRecord::Base
has_many :project_tags
has_many :tag_masters, :through => :project_tags
# Some more code and associations here..
end
我是 Rails 的新手并试图解决它,但我认为我无法改变我的联想。
我正在使用 rails 3.0.10
请帮帮我。
最佳答案
我认为我的联想是错误的。
class ProjectTag < ActiveRecord::Base
has_many :tag_masters
has_many :project_masters
end
代替has_many
;我不得不使用 belongs_to
。
关于ruby-on-rails-3 - 无法修改关联,因为源反射类通过 :has_many + rails 3. 0.10 关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8489325/