我有一个模型:
class Merchant < ActiveRecord::Base
belongs_to :billing_address, class_name: Address, dependent: :destroy
belongs_to :other_address1, class_name: Address, dependent: :destroy
belongs_to :other_address2, class_name: Address, dependent: :destroy
belongs_to :other_address3, class_name: Address, dependent: :destroy
belongs_to :other_address4, class_name: Address, dependent: :destroy
...
end
Address
没有关联。
当我这样做时:
merchant.billing_address.destroy
在数据库中,地址记录消失了,但merchants.billing_address_id
保留了一个虚假值。这是mysql,所以没有参照完整性。
我究竟做错了什么?
注意:我意识到这可能更好地建模为has_one
关联。我可能不得不去那里,但我不想去。
更新:添加了更多代码以显示多个地址关联。