title: Database relationship cycle
body: <p>Database relationship cycles smell like bad database design. Below is a situation in which I think it can not be prevented:</p>
  
  <ul>
  <li>a <em>Company</em> has <em>Locations</em> (City)</li>
  <li><p>a <em>Company</em> has <em>Products</em> (Big Mac)</p></li>
  <li><p><em>Products</em> are/are not available on <em>Locations</em> (No Bacon Burger in Saudia Arabia)  </p></li>
  </ul>
  
  <p>The current design would allow you to offer a <em>Product</em> that <strong>doesn't</strong> belong to this <em>Company</em> on a <em>Location</em> that <strong>does</strong> belong to this <em>Company</em>.</p>
  
  <p><strong>Company</strong><br>
  1 - McDonalds<br>
  2 - Burger King</p>
  
  <p><strong>Location</strong><br>
  1 - New York, building 1 - McDonalds (1)<br>
  2 - Amsterdam, building 2 - Burger King (2)</p>
  
  <p><strong>Product</strong><br>
  1 - Big Mac - McDonalds (1)</p>
  
  <p><strong>ProductLocation</strong><br>
  1 - Big Mac (1) - Amsterdam, building 2 (2)</p>
  
  <p>McDonalds sells Big Macs, Burger King doesn't, but it seems their building does :)<br>
  It becomes worse when we add relationships to <em>Product</em> that are also <em>Location</em> dependent.</p>
  
  <p>What can I do to prevent the cycle?<br>
  How do I ensure database data integrity?</p>