我不确定为什么这种关联无效
class Tag < ActiveRecord::Base
has_and_belongs_to_many :routes
end
class Route < ActiveRecord::Base
belongs_to :super_route
has_and_belongs_to_many :tags
end
class SuperRoute < ActiveRecord::Base
has_one :route
has_many :tags, through: :route
end
然后我希望能够做到以下
s = SuperRoute.create
s.route = Route.create
s.tags << Tag.create
除了抛出错误
ActiveRecord::HasManyThroughNestedAssociationsAreReadonly: Cannot modify association 'SuperRoute#tags' because it goes through more than one other association.
这里的根本错误是什么?
答案 0 :(得分:0)
class SuperRoute < ActiveRecord::Base
has_one :route
has_many :tags #remove through: :route
end