实现这一目标的更好方法是什么?
class Opf < ActiveRecord::Base
has_many :budget_items, dependent: :destroy, foreign_key: 'budget_id'
end
class Voucher < ActiveRecord::Base
has_many :budget_items, dependent: :destroy, foreign_key: 'budget_id'
end
class BudgetItem < ActiveRecord::Base
belongs_to :opf
belongs_to :voucher
end
Opf和Voucher可能有很多BudgetItem:
Opf.budget_items.build
Voucher.budget_items.build
我通过此设置获得的问题是它们共享相同的外键。