I’m creating a system that involves uploads. Now these uploads need to be attached to one of a manner of things eg. a message, a contract, a project
Is it okay to have one table for attachments then link them to these types – the caveat being that it needs to be linked to an individual id from each of these types
eg. in the attachment table
type – links to a table with the list of message contract etc
id. – an id # of what ever id for the type so if the type is message then it would refer to message.id if it was a contract it would refer to contract.id
but then there’s no foreign key checks? But it seems odd to have to do foreign keys eg.
type
message_id (FK)
contract_id (FK)
project_id (FK)
Edit: there’s a few more tables than 3 more like 5-6 perhaps more in future too..
I would recommend:
Example:
That way, you can have all the database integrity constraints with no unused columns.