gpt4 book ai didi

ruby-on-rails - 事件记录 : Cannot modify association because it goes through more than one other association

转载 作者:行者123 更新时间:2023-12-04 03:40:54 30 4
gpt4 key购买 nike

我不确定为什么这个关联无效

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.

这里的根本错误是什么?

最佳答案

class SuperRoute < ActiveRecord::Base
has_one :route
has_many :tags #remove through: :route
end

关于ruby-on-rails - 事件记录 : Cannot modify association because it goes through more than one other association,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46646691/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com