加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – ActiveRecord :: HasManyThroughOrderError

发布时间:2020-12-17 03:57:15 所属栏目:百科 来源:网络整理
导读:我在3个模型之间有一个has_one关联,但它有一个错误,上面写着“ActionView :: Template :: Error(不能有一个has_many:通过关联’Policy#intermed’,在通过关联之前通过’Policy#invoice’定义.)” 政策模式 class Policy ApplicationRecord self.table_name
我在3个模型之间有一个has_one关联,但它有一个错误,上面写着“ActionView :: Template :: Error(不能有一个has_many:通过关联’Policy#intermed’,在通过关联之前通过’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,foreign_key: :intrmdry_intm_no
has_one :invoice

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读