【问题标题】:The has_one :through Association! How Create connect between AccountHistory and Supplierhas_one :through 协会!如何在 AccountHistory 和 Supplier 之间建立连接
【发布时间】:2019-04-25 23:59:03
【问题描述】:
class Supplier < ApplicationRecord
  has_one :account
  has_one :account_history, through: :account
end

class Account < ApplicationRecord
  belongs_to :supplier
  has_one :account_history
end

class AccountHistory < ApplicationRecord
  belongs_to :account
end

由于某种原因,rails 6 无法在 SupplierAccountHistory 之间创建连接!

如果我们已经存在Supplier 和存在AccountHistory,需要示例如何创建此连接

【问题讨论】:

    标签: ruby-on-rails ruby associations


    【解决方案1】:

    谢谢大家,我已经找到解决办法了!

    Account.first.build_supplier(supplier_id: 1).save
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-04
      相关资源
      最近更新 更多