问题
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