我已经成功实现了一个友谊模型,它在创建友谊时会在数据库中创建两行。
# Accept a friend request.
def self.accept(customer, friend)
transaction do
accepted_at = Time.now
accept_one_side(customer, friend, accepted_at)
accept_one_side(friend, customer, accepted_at)
end
end
# Update the db with one side of an accepted friendship request.
def self.accept_one_side(customer, friend, accepted_at)
request = find_by_customer_id_and_friend_id(customer, friend)
request.status = 'accepted'
request.accepted_at = accepted_at
request.save!
end
现在当用户 A 删除他的帐户时,我如何确保数据库中的整个友谊(两行)也被删除。我相信dependent: destroy
只有在删除他的帐户后才会删除与用户 A 相关的数据。但我也希望删除属于用户 B 的数据库中的另一行。