has_one:通联!如何在 AccountHistory 和 Supplier 之间创建连接

The has_one :through Association! How Create connect between AccountHistory and Supplier

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

如何创建此连接

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

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