title: CakePHP 2 - Foreign key to many tables
body: <p>Please help with model associations.
  Schema looks like:
  <img src="https://i.stack.imgur.com/DbNG6.jpg" alt="Data model schema"></p>
  
  <p>translation_typeofs.typeof_id is typeof_[name] foreign key</p>
  
  <p>translation_typeofs.typeof_type content part of name of relation table (days, colours, buildings or rooms).</p>
  
  <p>TypeofDays model:</p>
  
  <pre><code>class TypeofDay extends AppModel {
      public $name = 'TypeofDay';
  
      public $hasMany = array(
          'GalleriesTypeofDay' =&gt; array(
              'className'  =&gt; 'GalleriesTypeofDay',
              'dependent' =&gt; true
          ),
          'TranslationTypeof' =&gt; array(
              'className'  =&gt; 'TranslationTypeof',
              'conditions' =&gt; array('TranslationTypeof.typeof_type' =&gt; 'days'),
              'dependent' =&gt; true
          )
      );
  }
  </code></pre>
  
  <p>TranslationTypeof model:</p>
  
  <pre><code>class TranslationTypeof extends AppModel {
      public $name = 'TranslationTypeof';
  
      public $belongsTo = array(
          'Language' =&gt; array(
              'className'    =&gt; 'Language',
              'foreignKey' =&gt; 'language_id',
          ),
          'TypeofBuilding' =&gt; array(
              'className'  =&gt; 'TypeofBuilding',
              'foreignKey' =&gt; 'typeof_id',
              'conditions' =&gt; array('TranslationTypeof.typeof_type' =&gt; 'buildings')
          ),
          'TypeofColour' =&gt; array(
              'className'  =&gt; 'TypeofColour',
              'foreignKey' =&gt; 'typeof_id',
              'conditions' =&gt; array('TranslationTypeof.typeof_type' =&gt; 'colours')
          ),
          'TypeofRoom' =&gt; array(
              'className'  =&gt; 'TypeofRoom',
              'foreignKey' =&gt; 'typeof_id',
              'conditions' =&gt; array('TranslationTypeof.typeof_type' =&gt; 'rooms')
          ),
          'TypeofDay' =&gt; array(
              'className'  =&gt; 'TypeofDay',
              'foreignKey' =&gt; 'typeof_id',
              'conditions' =&gt; array('TranslationTypeof.typeof_type' =&gt; 'days')
          )
      );
  }
  </code></pre>
  
  <p>When I try to save data</p>
  
  <pre><code>$this-&gt;TranslationTypeof-&gt;saveAll(array(
      'typeof_type'   =&gt; $this-&gt;data['type_name'],
      'typeof_id'     =&gt; $this-&gt;data['type_id'],
      'language_id'   =&gt; $languageId,
      'text'          =&gt; $translation
  ));
  </code></pre>
  
  <p>I'm getting error 500 (Internal Server Error) </p>
  
  <p>Error log:</p>
  
  <p>Error: [PDOException] SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (<code>schema</code>.<code>translation_typeofs</code>, CONSTRAINT <code>translation_typeofs_typeof_buildings_fkid1</code> FOREIGN KEY (<code>typeof_id</code>) REFERENCES <code>typeof_buildings</code> (<code>id</code>) ON DELETE NO ACTION ON UPDATE NO ACTION)</p>
  
  <p>I'm think that it's something with model association, but can't find the solution.</p>