title: CakePHP association one Model to exclusively one out of three others?
body: <p>i got a problem with designing my Database and the CakePHP code around it.</p>
  
  <p>I have 4 Models,</p>
  
  <ul>
  <li>ServerName</li>
  <li>VirtualMachine</li>
  <li>ServerHousing</li>
  <li>ManagedServer</li>
  </ul>
  
  <p>In ServerName, i want to save all ServerNames which then can be used in either one of the three other models. How can i achieve that i am only able to link one ServerName to either one of the other models?</p>
  
  <p>Thank you guys in advance.</p>
  
  <p>EDIT:</p>
  
  <p>I now did it a little bit different. First of all it need to be done in the Model itself.
  I used the validate option in cakePHP's models.</p>
  
  <p>The code is like this:</p>
  
  <pre><code>public $validate = array(
      'server_name_id' =&gt; array(
          'rule' =&gt; 'serverNameTaken',
          'message' =&gt; 'This Servername has already been taken.'
      )
  );
  
  public function serverNameTaken()
  {
      $this-&gt;ManagedServer = ClassRegistry::init("ManagedServer");
      // Assuming the server_name_id was passed from the form...
      $server_name_id = $this-&gt;data['VirtualMachine']['server_name_id'];
  
      // Check if this servername_id is already saved in virtual_machines
      if ($this-&gt;ManagedServer-&gt;find('count', array(
          'conditions' =&gt; array(
              'ManagedServer.server_name_id' =&gt; $server_name_id
          )
      )) &gt; 0
      ) {
          // Found the server_name in the VirtualMachine model!
          return false; // Prohibit saving the data
      }
  
      if ($this-&gt;find('count', array(
          'conditions' =&gt; array(
              'VirtualMachine.server_name_id' =&gt; $server_name_id
          )
      )) &gt; 0
      ) {
          // Found the server_name in the VirtualMachine model!
          return false; // Prohibit saving the data
      }
  
  
      // Do this for the other models too. If a return false is not hit by now,
      // everything should be fine and you can...
      return true;
  }
  </code></pre>
  
  <p>Same code I used in the other models, only the code had to be altered.</p>
  
  <p>Thanks again for you answer!!!</p>