gpt4 book ai didi

ruby-on-rails - ActiveRecord::HasManyThroughOrderError

转载 作者:行者123 更新时间:2023-12-03 16:12:09 27 4
gpt4 key购买 nike

我在 3 个模型之间有一个 has_one 关联,但它有一个错误说“ActionView::Template::Error(不能有一个 has_many :through association 'Policy#intermediary' 它在通过关联之前通过 'Policy#invoice'定义。)”

政策模式

class Policy < ApplicationRecord

self.table_name = "gipi_polbasic"
self.primary_key = "policy_id"

has_one :invoice
has_one :intermediary, through: :invoice, foreign_key: :intrmdry_intm_no

中介模式
class Intermediary < ApplicationRecord
self.table_name = "giis_intermediary"
self.primary_key = "intm_no"

has_one :invoice, foreign_key: :intrmdry_intm_no
belongs_to :policy, foreign_key: :policy_id

发票模型
class Invoice < ApplicationRecord
self.table_name = "gipi_comm_invoice"
self.primary_key = "intrmdry_intm_no"

belongs_to :policy, foreign_key: :policy_id
belongs_to :intermediary, foreign_key: :intrmdry_intm_no

最佳答案

对于其他人 - 请参阅他们的主题 https://github.com/rails/rails/issues/29123

为我解决的是切换 has_ones 的顺序

has_one :intermediary, through: :invoice, foreign_key: :intrmdry_intm_no
has_one :invoice

关于ruby-on-rails - ActiveRecord::HasManyThroughOrderError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44013983/

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