Exemple #1
0
 protected function relateI18nTableToMainTable()
 {
     $table = $this->getTable();
     $i18nTable = $this->i18nTable;
     $pks = $this->getTable()->getPrimaryKey();
     if (count($pks) > 1) {
         throw new EngineException('The i18n behavior does not support tables with composite primary keys');
     }
     foreach ($pks as $column) {
         if (!$i18nTable->hasColumn($column->getName())) {
             $column = clone $column;
             $column->setAutoIncrement(false);
             $i18nTable->addColumn($column);
         }
     }
     if (in_array($table->getName(), $i18nTable->getForeignTableNames())) {
         return;
     }
     $fk = new ForeignKey();
     $fk->setForeignTableCommonName($table->getCommonName());
     $fk->setForeignSchemaName($table->getSchema());
     $fk->setDefaultJoin('LEFT JOIN');
     $fk->setOnDelete(ForeignKey::CASCADE);
     $fk->setOnUpdate(ForeignKey::NONE);
     foreach ($pks as $column) {
         $fk->addReference($column->getName(), $column->getName());
     }
     $i18nTable->addForeignKey($fk);
 }
 protected function relateDelegateToMainTable($delegateTable, $mainTable)
 {
     $pks = $mainTable->getPrimaryKey();
     foreach ($pks as $column) {
         $mainColumnName = $column->getName();
         if (!$delegateTable->hasColumn($mainColumnName)) {
             $column = clone $column;
             $column->setAutoIncrement(false);
             $delegateTable->addColumn($column);
         }
     }
     // Add a one-to-one fk
     $fk = new ForeignKey();
     $fk->setForeignTableCommonName($mainTable->getCommonName());
     $fk->setForeignSchemaName($mainTable->getSchema());
     $fk->setDefaultJoin('LEFT JOIN');
     $fk->setOnDelete(ForeignKey::CASCADE);
     $fk->setOnUpdate(ForeignKey::NONE);
     foreach ($pks as $column) {
         $fk->addReference($column->getName(), $column->getName());
     }
     $delegateTable->addForeignKey($fk);
 }