title: Same table containing different types and different relationships with other tables based on that type
body: <p>suppose you're recreating the Facebook news feed and would like to have all data for that feed in a table called <code>Posts</code>. However, table <code>Posts</code> does not include text values only, but can hold <code>Posts</code> of type <code>text</code>, <code>notifications</code>, <code>images</code> and <code>videos</code>.</p>
  <p>Using a single table <code>Posts</code> as per the image attached. How can I cleanly define different <code>Post</code> types and relate a <code>Post</code> of <code>Image</code> type to the <code>Photos</code> table? Of course <strong>if that post was of type image! There shouldn't be any relationship if the post is of different type. Instead it should relate somewhere else in that case.</strong></p>
  <p><img src="https://i.stack.imgur.com/moJTP.png" alt="Highlighted Diagram PNG" /></p>
  <p>I thought about adding an extra field in the <code>Posts</code> table such as <code>Type</code> of type integer but I don't think that is an elegant solution.</p>
  <p>Any ideas?</p>
  <p>Thanks!</p>
  <p>EDIT
  <strong>Important note: The <code>Photos</code> table is also used to display images in a photo gallery whether that particular photo is to appear in the newsfeed or not  (table <code>Posts</code>), that feature is completely optional.</strong></p>