Example flow is on the image. Here I want to accomplish if playlist removed, make it delete image too.
I know I should’ve put FK on image table but Image is generic and its used more than once.
What are my options? Triggers and application-side comes to mind, but I’m not sure. Maybe there is a better way.
UPDATE: I guess I’ve found what I was looking for, rules:
CREATE RULE playlist_delete AS ON DELETE TO playlist WHERE (SELECT id FROM image WHERE image.id = OLD.image_id) IS NOT NULL DO INSTEAD NOTHING;
Looks like a trigger might be the right approach
https://stackoverflow.com/questions/53446075/cascading-delete-without-foreign-key-constraint-postgresql#53447913
I’ve been avoiding triggers, but I guess there’s no better alternative. Thanks.