title: Should I make another table that references unique IDs or just add a unique ID columns in Ruby on Rails?
body: <p>I am creating a social app that consists of the typical community feed like Instagram. Let's pretend it's an app for users to show off their houses. I have 5 tables/models that are made for separate concepts. An example would be, these made up names - <code>&quot;Food&quot;, &quot;House&quot;, &quot;Electronic&quot;, &quot;Person&quot;, &quot;Car&quot;</code>.</p>
  <p>The issue is we decided to have each of these displayed in our Community tab. Furthermore, if a user wants to take a picture of one of these items, there has to be 5 separate checks of logic. So the frontend has to check 5 different endpoints, essentially. Which can be a bit redundant and produce a lot of spaghetti code.</p>
  <p>I found two solutions. Both deal with using a UUID so the frontend has to only hit one endpoint.</p>
  <ol>
  <li><p>Add a <code>&quot;UUID&quot;</code> column to all 5, and create an endpoint that searches through the 5 tables. The issue is if I have the search to start on table <code>&quot;Car&quot;</code> every time, and that table has way more entries than the table I'm looking for - <code>&quot;Food&quot;</code>, the query would consistently be slow every time a user searches through the <code>&quot;Food&quot;</code> table.</p>
  </li>
  <li><p>Create a joins table that has a UUID column and has reference to the other tables. That way when querying the DB will not have to jump from table to table. I think this is the best way, but wanted to get other people's opinions before I make a decision.</p>
  </li>
  </ol>