Hello dear Stack Overflow community,
I searched many hours already but I couldn't find a solution my quite unique scenario.
Maybe you guys can help.
Let's assume we have two tables.
|domain_realm | | password_policy |
|-------------------------------- | | ---------------------------------------|
|id domain password_policy_id | | id min_chars min_numbers min_length |
|1 1 11 | | 11 3 2 |
|2 1 12 | | 12 4 1 |
One is called domain_realm
, the other one password_policy
.
It's a OneToOne relationship, therefore one domain_realm
has only one password_policy
.
Now comes the quite unique case in this scenario:
domain_realm
holds the password_policy_id
(more or less fk) instead of password_policy
holding the foreign key of it's parent.
Why would someone do this?
Let's assumepassword_policy
is part of a package for many other applications not working with domain realms. Therefore keeping the table clean of any specific rows no other application needs (e.g.fk_domain_relam
) is mandatory.
Now it seems to be impossible to automatically delete (ON DELETE CASCADE
) the correlating password_policy
when deleting a domain_realm
.
Is there a way to do this the SQL way or do I have to know this and make sure that password_policy
gets deleted in my code?
That would be quite nasty because if I have to delete a domain_realm
directly in the database (debug or support reasons) I've created an orphan and I have to know this. Otherwise the orphan will stay in that db forever.
Thank you very much up front and for even reading this.