Sample Header Ad - 728x90

How to handle the deletion of records with "shared ownership"?

0 votes
1 answer
37 views
Consider the following scenario: In a trading card game, a user may offer to trade their cards. The offer can be public (any user can accept, fk_receiver_id null on insert) or private (only one user can accept, fk_receiver_id set on insert). So we have the following junction table TradeOffer I want to allow users to delete their accounts. I would be happy to cascade delete most things, but the trades have two users associated so I cant just delete everything. I could make fk_offerer_id nullable and use ON DELETE SET NULL, but I dont want to allow null values on insert. Should I make fk_offerer_id nullable anyway? Is there a better solution? The behavior I'm looking for when deleting is: - If fk_receiver_id is set, set fk_offerer_id to NULL or other value that signals "deleted user" - If fk_receiver_id is NULL (trade is pending/cancelled), delete the record Is there a way to handle this in the db? (Ideally without triggers)
Asked by Fullaccess (1 rep)
Nov 27, 2024, 10:33 PM
Last activity: Nov 28, 2024, 01:39 PM