Say I have a ticket, and this ticket has an owner and a taker. The owner ID is set when the ticket is created, and the recipient ID is set to NULL by default. In this case, the receiver may NOT also be the owner. I know that this is trivial to do in the logic of progaming, but I wonder if this can be done in the database.
Setting two unique fields: UNIQUE(owner_id, taker_id);does not work, as the owner may have many tickets not accepted at the same time. Maybe a triple unique key along with a ticket identifier, but then I feel that there might be something missing in my design.
An added bonus would be to see how it would be done in Django
source
share