Exemplo n.º 1
0
 /**
  * @param ForeignKeyConstraint $constraint
  */
 protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint)
 {
     $constraint->setLocalTable($this);
     if (strlen($constraint->getName())) {
         $name = $constraint->getName();
     } else {
         $name = $this->_generateIdentifierName(array_merge((array) $this->getName(), $constraint->getLocalColumns()), "fk", $this->_getMaxIdentifierLength());
     }
     $name = strtolower($name);
     $this->_fkConstraints[$name] = $constraint;
     // add an explicit index on the foreign key columns. If there is already an index that fullfils this requirements drop the request.
     // In the case of __construct calling this method during hydration from schema-details all the explicitly added indexes
     // lead to duplicates. This creates compuation overhead in this case, however no duplicate indexes are ever added (based on columns).
     $this->addIndex($constraint->getColumns());
 }
Exemplo n.º 2
0
 /**
  * Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint
  * of a field declaration to be used in statements like CREATE TABLE.
  *
  * @param ForeignKeyConstraint $foreignKey
  * @return string
  */
 public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey)
 {
     $sql = '';
     if (strlen($foreignKey->getName())) {
         $sql .= 'CONSTRAINT ' . $foreignKey->getQuotedName($this) . ' ';
     }
     $sql .= 'FOREIGN KEY (';
     if (count($foreignKey->getLocalColumns()) == 0) {
         throw new \InvalidArgumentException("Incomplete definition. 'local' required.");
     }
     if (count($foreignKey->getForeignColumns()) == 0) {
         throw new \InvalidArgumentException("Incomplete definition. 'foreign' required.");
     }
     if (strlen($foreignKey->getForeignTableName()) == 0) {
         throw new \InvalidArgumentException("Incomplete definition. 'foreignTable' required.");
     }
     $sql .= implode(', ', $foreignKey->getLocalColumns()) . ') REFERENCES ' . $foreignKey->getForeignTableName() . ' (' . implode(', ', $foreignKey->getForeignColumns()) . ')';
     return $sql;
 }
Exemplo n.º 3
0
 /**
  * {@inheritdoc}
  */
 public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
 {
     $this->output .= $this->createNodeRelation($fkConstraint->getLocalTableName() . ":col" . current($fkConstraint->getLocalColumns()) . ":se", $fkConstraint->getForeignTableName() . ":col" . current($fkConstraint->getForeignColumns()) . ":se", array('dir' => 'back', 'arrowtail' => 'dot', 'arrowhead' => 'normal'));
 }
Exemplo n.º 4
0
 /**
  * @param ForeignKeyConstraint $constraint
  */
 protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint)
 {
     $constraint->setLocalTable($this);
     if (strlen($constraint->getName())) {
         $name = $constraint->getName();
     } else {
         $name = $this->_generateIdentifierName(array_merge((array) $this->getName(), $constraint->getLocalColumns()), "fk", $this->_getMaxIdentifierLength());
     }
     $name = strtolower($name);
     $this->_fkConstraints[$name] = $constraint;
 }
 /**
  * @param ForeignKeyConstraint $constraint
  *
  * @return void
  */
 protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint)
 {
     $constraint->setLocalTable($this);
     if (strlen($constraint->getName())) {
         $name = $constraint->getName();
     } else {
         $name = $this->_generateIdentifierName(array_merge((array) $this->getName(), $constraint->getLocalColumns()), "fk", $this->_getMaxIdentifierLength());
     }
     $name = $this->normalizeIdentifier($name);
     $this->_fkConstraints[$name] = $constraint;
     // add an explicit index on the foreign key columns. If there is already an index that fulfils this requirements drop the request.
     // In the case of __construct calling this method during hydration from schema-details all the explicitly added indexes
     // lead to duplicates. This creates computation overhead in this case, however no duplicate indexes are ever added (based on columns).
     $indexName = $this->_generateIdentifierName(array_merge(array($this->getName()), $constraint->getColumns()), "idx", $this->_getMaxIdentifierLength());
     $indexCandidate = $this->_createIndex($constraint->getColumns(), $indexName, false, false);
     foreach ($this->_indexes as $existingIndex) {
         if ($indexCandidate->isFullfilledBy($existingIndex)) {
             return;
         }
     }
     $this->_addIndex($indexCandidate);
     $this->implicitIndexes[$this->normalizeIdentifier($indexName)] = $indexCandidate;
 }
Exemplo n.º 6
0
 /**
  * {@inheritDoc}
  */
 public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey)
 {
     return parent::getForeignKeyDeclarationSQL(new ForeignKeyConstraint($foreignKey->getLocalColumns(), str_replace('.', '__', $foreignKey->getForeignTableName()), $foreignKey->getForeignColumns(), $foreignKey->getName(), $foreignKey->getOptions()));
 }
Exemplo n.º 7
0
 /**
  * Creates a foreign index replacement, which has quoted column names.
  *
  * @param ForeignKeyConstraint $fk
  *
  * @return ForeignKeyConstraint
  */
 private function createForeignKeyReplacement(ForeignKeyConstraint $fk)
 {
     return new ForeignKeyConstraint($this->quoteIdentifiers($fk->getLocalColumns()), $this->platform->quoteIdentifier($fk->getForeignTableName()), $this->quoteIdentifiers($fk->getForeignColumns()), $this->platform->quoteIdentifier($fk->getName()), $fk->getOptions());
 }
Exemplo n.º 8
0
 /**
  * Accept a foreign key for a table
  *
  * @param Table                $localTable   a table object
  * @param ForeignKeyConstraint $fkConstraint a constraint object
  * 
  * @return void
  */
 public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
 {
     if (!isset($this->schemaArray['tables'][$localTable->getName()]['constraint'])) {
         $this->schemaArray['tables'][$localTable->getName()]['constraint'] = array();
     }
     $this->schemaArray['tables'][$localTable->getName()]['constraint'][] = array('name' => $fkConstraint->getName(), 'localcolumns' => $fkConstraint->getLocalColumns(), 'foreigntable' => $fkConstraint->getForeignTableName(), 'foreigncolumns' => $fkConstraint->getForeignColumns(), 'options' => $fkConstraint->getOptions());
 }