title: CRM Releationships MySQL
body: <p><em>Our Company is developing a CRM and we came now to the point where we have to decide how we want to handle the releationships. This is an important point because there are going to be tons of them. And changing the structure later would be simply not cool..</em></p>
  
  <p><em>I know 3 ways how we could do it:</em></p>
  
  <p><strong>One releationship table:</strong></p>
  
  <p>The way i would do this is creating one table holding all the releationships.</p>
  
  <pre><code>Table: releationships
  
  +----+-------------+-----------+--------------+------------+
  | id | record_type | record_id | belongs_type | belongs_id |
  +----+-------------+-----------+--------------+------------+
  | 1  | person      | 42        | company      | 12         |
  +----+-------------+-----------+--------------+------------+
  | 2  | person      | 43        | company      | 12         |
  +----+-------------+-----------+--------------+------------+
  | 3  | note        | 23        | company      | 12         |
  +----+-------------+-----------+--------------+------------+ 
  | 4  | attachment  | 13        | company      | 12         |
  +----+-------------+-----------+--------------+------------+
  </code></pre>
  
  <p><strong>Multiple releationship tables:</strong></p>
  
  <p>I think this is the way how it for example the SugarCRM does.</p>
  
  <pre><code>Table: company_realationships
  
  +----+-----------+------------+--------+
  | id | record_id | has_type   | has_id |
  +----+-----------+------------+--------+
  | 1  | 12        | person     | 42     |
  +----+-----------+------------+--------+
  | 2  | 12        | person     | 43     |
  +----+-----------+------------+--------+
  | 3  | 12        | note       | 23     |
  +----+-----------+------------+--------+
  | 2  | 12        | attachment | 13     |
  +----+-----------+------------+--------+
  </code></pre>
  
  <p><strong>All in the record table:</strong></p>
  
  <pre><code>Table: person
  
  +----+-----------+------------+
  | id | name      | company_id |
  +----+-----------+------------+
  | 42 | luke      | 12         |
  +----+-----------+------------+
  | 43 | other guy | 12         |
  +----+-----------+------------+
  </code></pre>
  
  <p>ect.</p>
  
  <ul>
  <li>So my Question is wich is the <strong>Best</strong> way of handling lots of releationships?</li>
  <li>Are there other ways to do it?</li>
  <li>What are disadvantages / advantages?</li>
  <li>Is there a special way how hightraffic sides handle their releationships?</li>
  </ul>
  
  <p>Thanks for your help guys :)</p>