コード例 #1
0
 private function reverseEngineerMappingFromDatabase()
 {
     if ($this->tables !== null) {
         return;
     }
     foreach ($this->_sm->listTableNames() as $tableName) {
         $tables[strtolower($tableName)] = $this->_sm->listTableDetails($tableName);
     }
     $this->tables = array();
     foreach ($tables as $name => $table) {
         /* @var $table Table */
         if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
             $foreignKeys = $table->getForeignKeys();
         } else {
             $foreignKeys = array();
         }
         $allForeignKeyColumns = array();
         foreach ($foreignKeys as $foreignKey) {
             $allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns());
         }
         $pkColumns = $table->getPrimaryKey()->getColumns();
         sort($pkColumns);
         sort($allForeignKeyColumns);
         if ($pkColumns == $allForeignKeyColumns) {
             if (count($table->getForeignKeys()) > 2) {
                 throw new \InvalidArgumentException("ManyToMany table '" . $name . "' with more or less than two foreign keys are not supported by the Database Reverese Engineering Driver.");
             }
             $this->manyToManyTables[$name] = $table;
         } else {
             $className = Inflector::classify($name);
             $this->tables[$name] = $table;
             $this->classes[$className] = $name;
         }
     }
 }
コード例 #2
0
 private function reverseEngineerMappingFromDatabase()
 {
     if ($this->tables !== null) {
         return;
     }
     foreach ($this->_sm->listTableNames() as $tableName) {
         $tables[$tableName] = $this->_sm->listTableDetails($tableName);
     }
     $this->tables = $this->manyToManyTables = $this->classToTableNames = array();
     foreach ($tables as $tableName => $table) {
         /* @var $table Table */
         if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
             $foreignKeys = $table->getForeignKeys();
         } else {
             $foreignKeys = array();
         }
         $allForeignKeyColumns = array();
         foreach ($foreignKeys as $foreignKey) {
             $allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns());
         }
         $pkColumns = $table->getPrimaryKey()->getColumns();
         sort($pkColumns);
         sort($allForeignKeyColumns);
         if ($pkColumns == $allForeignKeyColumns && count($foreignKeys) == 2) {
             $this->manyToManyTables[$tableName] = $table;
         } else {
             // lower-casing is necessary because of Oracle Uppercase Tablenames,
             // assumption is lower-case + underscore separated.
             $className = Inflector::classify(strtolower($tableName));
             $this->tables[$tableName] = $table;
             $this->classToTableNames[$className] = $tableName;
         }
     }
 }
コード例 #3
0
 /**
  * @return void
  *
  * @throws \Doctrine\ORM\Mapping\MappingException
  */
 private function reverseEngineerMappingFromDatabase()
 {
     if ($this->tables !== null) {
         return;
     }
     $tables = array();
     foreach ($this->_sm->listTableNames() as $tableName) {
         $tables[$tableName] = $this->_sm->listTableDetails($tableName);
     }
     $this->tables = $this->manyToManyTables = $this->classToTableNames = array();
     foreach ($tables as $tableName => $table) {
         $foreignKeys = $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints() ? $table->getForeignKeys() : array();
         $allForeignKeyColumns = array();
         foreach ($foreignKeys as $foreignKey) {
             $allForeignKeyColumns = array_merge($allForeignKeyColumns, $foreignKey->getLocalColumns());
         }
         if (!$table->hasPrimaryKey()) {
             throw new MappingException("Table " . $table->getName() . " has no primary key. Doctrine does not " . "support reverse engineering from tables that don't have a primary key.");
         }
         $pkColumns = $table->getPrimaryKey()->getColumns();
         sort($pkColumns);
         sort($allForeignKeyColumns);
         if ($pkColumns == $allForeignKeyColumns && count($foreignKeys) == 2) {
             $this->manyToManyTables[$tableName] = $table;
         } else {
             // lower-casing is necessary because of Oracle Uppercase Tablenames,
             // assumption is lower-case + underscore separated.
             $className = $this->getClassNameForTable($tableName);
             $this->tables[$tableName] = $table;
             $this->classToTableNames[$className] = $tableName;
         }
     }
 }
コード例 #4
0
 /**
  * @return mixed
  */
 public function getTables()
 {
     return $this->schema->listTableNames();
 }
コード例 #5
0
 public function tearDown()
 {
     foreach ($this->_sm->listTableNames() as $tableName) {
         $this->_sm->dropTable($tableName);
     }
 }