1
我不知道爲什麼這個協會是無效ActiveRecord的:因爲它通過一個以上的其他關聯不能修改協會
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.
什麼是這裏的根本性的錯誤?
這意味着SuperRoute和Tag類之間的外鍵關係,這正是我試圖避免的。 – rkachowski