Back

One-to-one relationship on delete

  • 0
  • Databases
Said H
29 Jan, 2024, 04:37

Hello, I have a parent table called asset and a child table called user. user table has a 1-1 relationship with asset as 1 user can only use 1 asset. And 1 asset can only belong to 1 user.

The thing is, at the point of asset creation, it is possible that there is no user yet until after some times, which means user could potentially be empty for a long time.

Now, I want to set up a relationship such that if I delete an asset, it will delete the user too. I have set up the relationship as Cascade. But, I noticed that when I delete the user, it also deletes the asset, which I don't want.

How do I set it such that:

  • If I delete asset, it deletes its associated user
  • If I delete user, nothing happens to asset
TL;DR
The developer wants to set up a one-to-one relationship between the `asset` and `user` tables. They want to ensure that deleting an `asset` will also delete the associated `user`, but deleting a `user` will not affect the `asset`. To achieve this, the developer should set up a one-to-one relationship with the DELETE CASCADE option from the `asset` table to the `user` table. This way, deleting an `asset` will automatically delete its associated `user`. However, the relationship from the `user` table to the `asset` table should not have any delete actions defined, so deleting
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more