예제 #1
0
 /**
  * Gathers the SQL for properly setting up the relations of the given class.
  * This includes the SQL for foreign key constraints and join tables.
  *
  * @param ClassMetadata $class
  * @param \Doctrine\DBAL\Schema\Table $table
  * @param \Doctrine\DBAL\Schema\Schema $schema
  * @return void
  */
 private function _gatherRelationsSql($class, $table, $schema)
 {
     foreach ($class->associationMappings as $fieldName => $mapping) {
         if (isset($class->inheritedAssociationFields[$fieldName])) {
             continue;
         }
         $foreignClass = $this->_em->getClassMetadata($mapping->targetEntityName);
         if ($mapping->isOneToOne() && $mapping->isOwningSide) {
             $primaryKeyColumns = $uniqueConstraints = array();
             // unnecessary for this relation-type
             $this->_gatherRelationJoinColumns($mapping->joinColumns, $table, $foreignClass, $mapping, $primaryKeyColumns, $uniqueConstraints);
         } else {
             if ($mapping->isOneToMany() && $mapping->isOwningSide) {
                 //... create join table, one-many through join table supported later
                 throw ORMException::notSupported();
             } else {
                 if ($mapping->isManyToMany() && $mapping->isOwningSide) {
                     // create join table
                     $joinTable = $mapping->joinTable;
                     $theJoinTable = $schema->createTable($mapping->getQuotedJoinTableName($this->_platform));
                     $primaryKeyColumns = $uniqueConstraints = array();
                     // Build first FK constraint (relation table => source table)
                     $this->_gatherRelationJoinColumns($joinTable['joinColumns'], $theJoinTable, $class, $mapping, $primaryKeyColumns, $uniqueConstraints);
                     // Build second FK constraint (relation table => target table)
                     $this->_gatherRelationJoinColumns($joinTable['inverseJoinColumns'], $theJoinTable, $foreignClass, $mapping, $primaryKeyColumns, $uniqueConstraints);
                     foreach ($uniqueConstraints as $indexName => $unique) {
                         $theJoinTable->addUniqueIndex($unique['columns'], is_numeric($indexName) ? null : $indexName);
                     }
                     $theJoinTable->setPrimaryKey($primaryKeyColumns);
                 }
             }
         }
     }
 }
예제 #2
0
 /**
  * Gathers the SQL for properly setting up the relations of the given class.
  * This includes the SQL for foreign key constraints and join tables.
  *
  * @param ClassMetadata $class
  * @param \Doctrine\DBAL\Schema\Table $table
  * @param \Doctrine\DBAL\Schema\Schema $schema
  * @return void
  */
 private function _gatherRelationsSql($class, $table, $schema)
 {
     foreach ($class->associationMappings as $fieldName => $mapping) {
         if (isset($mapping['inherited'])) {
             continue;
         }
         $foreignClass = $this->em->getClassMetadata($mapping['targetEntity']);
         if ($mapping['type'] & ClassMetadata::TO_ONE && $mapping['isOwningSide']) {
             $primaryKeyColumns = $uniqueConstraints = array();
             // PK is unnecessary for this relation-type
             $this->_gatherRelationJoinColumns($mapping['joinColumns'], $table, $foreignClass, $mapping, $primaryKeyColumns, $uniqueConstraints);
             foreach ($uniqueConstraints as $indexName => $unique) {
                 $table->addUniqueIndex($unique['columns'], is_numeric($indexName) ? null : $indexName);
             }
         } else {
             if ($mapping['type'] == ClassMetadata::ONE_TO_MANY && $mapping['isOwningSide']) {
                 //... create join table, one-many through join table supported later
                 throw ORMException::notSupported();
             } else {
                 if ($mapping['type'] == ClassMetadata::MANY_TO_MANY && $mapping['isOwningSide']) {
                     // create join table
                     $joinTable = $mapping['joinTable'];
                     $theJoinTable = $schema->createTable($this->quoteStrategy->getJoinTableName($mapping, $foreignClass, $this->platform));
                     $primaryKeyColumns = $uniqueConstraints = array();
                     // Build first FK constraint (relation table => source table)
                     $this->_gatherRelationJoinColumns($joinTable['joinColumns'], $theJoinTable, $class, $mapping, $primaryKeyColumns, $uniqueConstraints);
                     // Build second FK constraint (relation table => target table)
                     $this->_gatherRelationJoinColumns($joinTable['inverseJoinColumns'], $theJoinTable, $foreignClass, $mapping, $primaryKeyColumns, $uniqueConstraints);
                     $theJoinTable->setPrimaryKey($primaryKeyColumns);
                     foreach ($uniqueConstraints as $indexName => $unique) {
                         $theJoinTable->addUniqueIndex($unique['columns'], is_numeric($indexName) ? null : $indexName);
                     }
                 }
             }
         }
     }
 }
예제 #3
0
 /**
  * Gathers the SQL for properly setting up the relations of the given class.
  * This includes the SQL for foreign key constraints and join tables.
  *
  * @param ClassMetadata $class
  * @param Table         $table
  * @param Schema        $schema
  * @param array         $addedFks
  * @param array         $blacklistedFks
  *
  * @return void
  *
  * @throws \Doctrine\ORM\ORMException
  */
 private function gatherRelationsSql($class, $table, $schema, &$addedFks, &$blacklistedFks)
 {
     foreach ($class->associationMappings as $mapping) {
         if (isset($mapping['inherited'])) {
             continue;
         }
         $foreignClass = $this->em->getClassMetadata($mapping['targetEntity']);
         if ($mapping['type'] & ClassMetadata::TO_ONE && $mapping['isOwningSide']) {
             $primaryKeyColumns = [];
             // PK is unnecessary for this relation-type
             $this->gatherRelationJoinColumns($mapping['joinColumns'], $table, $foreignClass, $mapping, $primaryKeyColumns, $addedFks, $blacklistedFks);
         } elseif ($mapping['type'] == ClassMetadata::ONE_TO_MANY && $mapping['isOwningSide']) {
             //... create join table, one-many through join table supported later
             throw ORMException::notSupported();
         } elseif ($mapping['type'] == ClassMetadata::MANY_TO_MANY && $mapping['isOwningSide']) {
             // create join table
             $joinTable = $mapping['joinTable'];
             $theJoinTable = $schema->createTable($this->quoteStrategy->getJoinTableName($mapping, $foreignClass, $this->platform));
             $primaryKeyColumns = [];
             // Build first FK constraint (relation table => source table)
             $this->gatherRelationJoinColumns($joinTable['joinColumns'], $theJoinTable, $class, $mapping, $primaryKeyColumns, $addedFks, $blacklistedFks);
             // Build second FK constraint (relation table => target table)
             $this->gatherRelationJoinColumns($joinTable['inverseJoinColumns'], $theJoinTable, $foreignClass, $mapping, $primaryKeyColumns, $addedFks, $blacklistedFks);
             $theJoinTable->setPrimaryKey($primaryKeyColumns);
         }
     }
 }