Cannot modify association because the source reflection class is associated to via :has_many + rails 3.0.10

时光总嘲笑我的痴心妄想 提交于 2020-01-13 22:40:13

问题


Getting Following Error ActiveRecord::HasManyThroughCantAssociateThroughHasOneOrManyReflection in ProjectController#create

Cannot modify association 'ProjectMaster#tag_masters' because the source reflection class 'TagMaster' is associated to 'ProjectTag' via :has_many.

Following are my models.

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

I am new to rails and tried to solve it but I don't think i can change my associations.

I am using rails 3.0.10

Please help me out here.

  • Thanks

回答1:


I think my associations were wrong.

class ProjectTag < ActiveRecord::Base
  has_many :tag_masters 
  has_many :project_masters 
end

instead of has_many; I had to use belongs_to.



来源:https://stackoverflow.com/questions/8489325/cannot-modify-association-because-the-source-reflection-class-is-associated-to-v

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!