I currently am working with a database for a social media application. The database is running on postgresql, and I have ran into a logic issue.
I have two different types of content that can be submitted, topics, and posts. Each of these with their own primary key.
All of these have items can have some media attached to them. In my media table I have the columns content_type_id and content_id where content type is a key in a look up table with the different types of content, and the content_id is the primary key in the table where that particular piece of content is stored.
The issue I have ran into is that I cannot create a foreign key on content_id because depending on content_type it could be referring to one of two tables. Is there a way that I can set up a foreign key to look at the proper table depending on the value of the content_type_id column?