I need to model an smtp server configuration for various entities that can send email, so I have a table with the settings for an smtp server.
For example: entities that send email are “rooms” and “servers” — they live in separate tables since they have little in common, but they each refer to an optional email configuration.
While it is simple to have a SmtpConfigId in both the rooms and servers table, I cannot see how to have a cascading delete where, if the room or server is deleted, then its corresponding smtp configuration is also deleted.
Of course, I could replicate the smtp configuration fields for each entity table that can send an email, I think that the business logic for sending mail would be simplified if the email config is in its own table.
In addition to the email configuration, which is 1:1 between entities that send email, and their smtp configuration, there is also the question of form letters, which is 1:M, and I would also like a cascading delete to clean up the form letters if the entity that created them is deleted.
Am I thinking about this problem in the right way, and what is a good way to model it? on delete triggers?
I would consider modeling as a polymorphic relationship with one table being used for the config stuff with a smtp_type field to distinguish the types (room, server, etc.).