title: Relational Mapping between two Dynamic Amounts of Entities
body: <p>I have two amounts of dynamic entities. For example
  B1, B2, B3, B4, B5,... I don't know how many B's i have but i will have a specific table in SQL for each B. On the other hand i have a dynamic amount of A's each represented as a single row in Table AEnum.</p>
  
  <p>Now i want to have a Mapping. The mapping looks like that:
  Each a can have each entity of B or not => 1/0 => boolean.</p>
  
  <p>For example:</p>
  
  <pre><code>A1 =&gt; B1 (true), B2 (true), B3 (false), B4 (true)...
  A2 =&gt; B1 (true), B2 (false), B3 (false), B4 (true)...
  A3 =&gt; B1 (false), B2 (true), B3 (true), B4 (true)...
  </code></pre>
  
  <p>So for each B i made a column with B's name in the Table AHasB, just storing a tinyint. This is however not very dynamic. I want to make it as dynamic as possible.</p>
  
  <p>Possible idea:
  Table BEnum stores Bid and BName (the Tablename of B's instance), AEnum stays the same just being a number of rows storing stuff about each A. Then AHasB would look like:</p>
  
  <pre><code>A1 =&gt; "B1, B4, B12"
  A2 =&gt; "B9, B10"
  </code></pre>
  
  <p>Just storing it as a single string which i parse on the logic side, not the persistence side. With that solution the following would be the case:</p>
  
  <ul>
  <li>When adding a B: I only need to add the B table manually and update the BEnum table </li>
  <li>When deleting a B: Delete the table, update the BEnum table accordingly and update AHasB to delete all B instances out of the strings that just have been deleted</li>
  <li>When adding a A: Just insert a new row in AHasB</li>
  <li>When deleting an A: Just remove that row</li>
  </ul>
  
  <p>I think that would be the most dynamic approach. Or is there any better way to save this in a SQL database?</p>
  
  <p>If anyone asks: B1, B2, B3,... are all names for quite different tables. For example: cars, hobbys, etc. A1, A2, A3, are persons and the relation can be read as "For person X i want to know which hobbies he has, what cars he drives, etc."</p>
  
  <p>Someone any better ideas?</p>