当前位置: 首页>>代码示例>>PHP>>正文


PHP AbstractSchemaManager::listTableForeignKeys方法代码示例

本文整理汇总了PHP中Doctrine\DBAL\Schema\AbstractSchemaManager::listTableForeignKeys方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractSchemaManager::listTableForeignKeys方法的具体用法?PHP AbstractSchemaManager::listTableForeignKeys怎么用?PHP AbstractSchemaManager::listTableForeignKeys使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\DBAL\Schema\AbstractSchemaManager的用法示例。


在下文中一共展示了AbstractSchemaManager::listTableForeignKeys方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testCompositeForeignKeys

 public function testCompositeForeignKeys()
 {
     $this->conn->expects($this->once())->method('fetchAll')->will($this->returnValue($this->getFKDefinition()));
     $fkeys = $this->manager->listTableForeignKeys('dummy');
     $this->assertEquals(1, count($fkeys), "Table has to have one foreign key.");
     $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\ForeignKeyConstraint', $fkeys[0]);
     $this->assertEquals(array('column_1', 'column_2', 'column_3'), array_map('strtolower', $fkeys[0]->getLocalColumns()));
     $this->assertEquals(array('column_1', 'column_2', 'column_3'), array_map('strtolower', $fkeys[0]->getForeignColumns()));
 }
开发者ID:barbondev,项目名称:mysql4-doctrine-driver,代码行数:9,代码来源:MySQL4SchemaManagerTest.php

示例2: getForeignKeyConstraint

 /**
  * @param string $table
  * @param string $column
  * @return string
  * @throws \Exception
  */
 private function getForeignKeyConstraint($table, $column)
 {
     $keys = $this->schemaManager->listTableForeignKeys($table);
     foreach ($keys as $key) {
         if (in_array($column, $key->getLocalColumns(), false)) {
             return $key->getName();
         }
     }
     throw new \Exception('Foreign key constraint not found.');
 }
开发者ID:shopwareLabs,项目名称:SwagImportExport,代码行数:16,代码来源:Update02RemoveForeignKeyConstraint.php

示例3: getForeign

 /**
  * Get data based on foreign keys information from table.
  *
  * @param string $table
  * @param string|null $database
  * @return array
  */
 public function getForeign($table, $database = null)
 {
     $foreignData = [];
     foreach ($this->schema->listTableForeignKeys($table, $database) as $foreign) {
         $localColumns = $foreign->getLocalColumns();
         $referencesColumns = $foreign->getForeignColumns();
         $indexName = $foreign->getName();
         $defaultIndexName = implode('_', [$table, reset($localColumns), 'foreign']);
         $foreignData[reset($localColumns)] = ['dropForeignKey' => $indexName, 'name' => $indexName != $defaultIndexName ? $indexName : null, 'references' => reset($referencesColumns), 'on' => $foreign->getForeignTableName(), 'onDelete' => $foreign->onDelete(), 'onUpdate' => $foreign->onUpdate()];
     }
     return $foreignData;
 }
开发者ID:bebnev,项目名称:laravel-schema-parser,代码行数:19,代码来源:SchemaAdapter.php

示例4: testListForeignKeys

    public function testListForeignKeys()
    {
        if(!$this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) {
            $this->markTestSkipped('Does not support foreign key constraints.');
        }

        $this->createTestTable('test_create_fk1');
        $this->createTestTable('test_create_fk2');

        $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(
            array('foreign_key_test'), 'test_create_fk2', array('id'), 'foreign_key_test_fk', array('onDelete' => 'CASCADE')
        );

        $this->_sm->createForeignKey($foreignKey, 'test_create_fk1');

        $fkeys = $this->_sm->listTableForeignKeys('test_create_fk1');

        $this->assertEquals(1, count($fkeys), "Table 'test_create_fk1' has to have one foreign key.");
        
        $this->assertType('Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkeys[0]);
        $this->assertEquals(array('foreign_key_test'),  array_map('strtolower', $fkeys[0]->getLocalColumns()));
        $this->assertEquals(array('id'),                array_map('strtolower', $fkeys[0]->getForeignColumns()));
        $this->assertEquals('test_create_fk2',          strtolower($fkeys[0]->getForeignTableName()));

        if($fkeys[0]->hasOption('onDelete')) {
            $this->assertEquals('CASCADE', $fkeys[0]->getOption('onDelete'));
        }
    }
开发者ID:pmjones,项目名称:php-framework-benchmarks,代码行数:28,代码来源:SchemaManagerFunctionalTestCase.php

示例5: checkForForeignKeySourceTable

 public function checkForForeignKeySourceTable($columnName)
 {
     // @var Doctrine\DBAL\Schema\ForeignKeyConstraint[]
     $fks = $this->schema->listTableForeignKeys($this->table->getName());
     foreach ($fks as $f) {
         if (in_array($columnName, $f->getColumns())) {
             return $f->getForeignTableName();
         }
     }
     return '';
 }
开发者ID:jonphipps,项目名称:laravel-api-test,代码行数:11,代码来源:TableFieldsGenerator.php

示例6: getForeignKey

 /**
  * @param $name
  * @return \Doctrine\DBAL\Schema\ForeignKeyConstraint|null
  */
 protected function getForeignKey($name)
 {
     $foreignKeys = $this->schemaManager->listTableForeignKeys($this->table);
     foreach ($foreignKeys as $foreignKey) {
         foreach ($foreignKey->getLocalColumns() as $localColumn) {
             if ($localColumn === $name) {
                 return $foreignKey;
             }
         }
     }
     return null;
 }
开发者ID:DimaPikash,项目名称:eshop,代码行数:16,代码来源:ModelCompiler.php

示例7: generate

 /**
  * Get array of foreign keys
  *
  * @param string                                      $table Table Name
  * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $schema
  *
  * @return array
  */
 public function generate($table, $schema)
 {
     $this->table = $table;
     $fields = [];
     $foreignKeys = $schema->listTableForeignKeys($table);
     if (empty($foreignKeys)) {
         return array();
     }
     foreach ($foreignKeys as $foreignKey) {
         $fields[] = ['name' => $this->getName($foreignKey), 'field' => $foreignKey->getLocalColumns()[0], 'references' => $foreignKey->getForeignColumns()[0], 'on' => $foreignKey->getForeignTableName(), 'onUpdate' => $foreignKey->hasOption('onUpdate') ? $foreignKey->getOption('onUpdate') : 'RESTRICT', 'onDelete' => $foreignKey->hasOption('onDelete') ? $foreignKey->getOption('onDelete') : 'RESTRICT'];
     }
     return $fields;
 }
开发者ID:Goopil,项目名称:laravel-generator,代码行数:21,代码来源:ForeignKeyParser.php

示例8: testListForeignKeysComposite

 public function testListForeignKeysComposite()
 {
     if (!$this->_conn->getDatabasePlatform()->supportsForeignKeyConstraints()) {
         $this->markTestSkipped('Does not support foreign key constraints.');
     }
     $this->_sm->createTable($this->getTestTable('test_create_fk3'));
     $this->_sm->createTable($this->getTestCompositeTable('test_create_fk4'));
     $foreignKey = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('id', 'foreign_key_test'), 'test_create_fk4', array('id', 'other_id'), 'foreign_key_test_fk');
     $this->_sm->createForeignKey($foreignKey, 'test_create_fk3');
     $fkeys = $this->_sm->listTableForeignKeys('test_create_fk3');
     $this->assertEquals(1, count($fkeys), "Table 'test_create_fk3' has to have one foreign key.");
     $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\ForeignKeyConstraint', $fkeys[0]);
     $this->assertEquals(array('id', 'foreign_key_test'), array_map('strtolower', $fkeys[0]->getLocalColumns()));
     $this->assertEquals(array('id', 'other_id'), array_map('strtolower', $fkeys[0]->getForeignColumns()));
 }
开发者ID:llinder,项目名称:FrameworkBenchmarks,代码行数:15,代码来源:SchemaManagerFunctionalTestCase.php

示例9: checkPivots

 /**
  * return the the interesect on primary index and foreign key.
  * if we have 2 primary key that are also foreign key without a type field it should be a pivot table !
  *
  * @param $table
  * @return array
  */
 public function checkPivots($table)
 {
     $foreignKeys = $this->schema->listTableForeignKeys($table);
     $indexes = $this->schema->listTableIndexes($table);
     $toto = [];
     foreach ($foreignKeys as $key) {
         $toto[] = $key->getLocalColumns();
     }
     $tata = [];
     foreach ($indexes as $key) {
         if ($key->isPrimary()) {
             $tata[] = $key->getColumns();
         }
     }
     return array_intersect(array_flatten($toto), array_flatten($tata));
 }
开发者ID:Goopil,项目名称:laravel-generator,代码行数:23,代码来源:SchemaParser.php

示例10: setRelations

 /**
  * @param EloquentModel $model
  * @return $this
  */
 protected function setRelations(EloquentModel $model)
 {
     $foreignKeys = $this->manager->listTableForeignKeys($this->addPrefix($model->getTableName()));
     foreach ($foreignKeys as $tableForeignKey) {
         $tableForeignColumns = $tableForeignKey->getForeignColumns();
         if (count($tableForeignColumns) !== 1) {
             continue;
         }
         $relation = new BelongsTo($this->cropPrefix($tableForeignKey->getForeignTableName()), $tableForeignKey->getLocalColumns()[0], $tableForeignColumns[0]);
         $model->addRelation($relation);
     }
     $tables = $this->manager->listTables();
     foreach ($tables as $table) {
         if ($table->getName() === $this->addPrefix($model->getTableName())) {
             continue;
         }
         $foreignKeys = $table->getForeignKeys();
         foreach ($foreignKeys as $name => $foreignKey) {
             if ($foreignKey->getForeignTableName() === $this->addPrefix($model->getTableName())) {
                 $localColumns = $foreignKey->getLocalColumns();
                 if (count($localColumns) !== 1) {
                     continue;
                 }
                 if (count($foreignKeys) === 2 && count($table->getColumns()) >= 2) {
                     $keys = array_keys($foreignKeys);
                     $key = array_search($name, $keys) === 0 ? 1 : 0;
                     $secondForeignKey = $foreignKeys[$keys[$key]];
                     $secondForeignTable = $secondForeignKey->getForeignTableName();
                     $relation = new BelongsToMany($this->cropPrefix($secondForeignTable), $table->getName(), $localColumns[0], $secondForeignKey->getLocalColumns()[0]);
                     $model->addRelation($relation);
                     break;
                 } else {
                     $tableName = $this->cropPrefix($foreignKey->getLocalTableName());
                     $foreignColumn = $localColumns[0];
                     $localColumn = $foreignKey->getForeignColumns()[0];
                     if ($this->isColumnUnique($table, $foreignColumn)) {
                         $relation = new HasOne($tableName, $foreignColumn, $localColumn);
                     } else {
                         $relation = new HasMany($tableName, $foreignColumn, $localColumn);
                     }
                     $model->addRelation($relation);
                 }
             }
         }
     }
     return $this;
 }
开发者ID:xvlady,项目名称:eloquent-model-generator,代码行数:51,代码来源:EloquentModelBuilder.php

示例11: testListTableDetailsWithFullQualifiedTableName

 public function testListTableDetailsWithFullQualifiedTableName()
 {
     if (!$this->_sm->getDatabasePlatform()->supportsSchemas()) {
         $this->markTestSkipped('Test only works on platforms that support schemas.');
     }
     $defaultSchemaName = $this->_sm->getDatabasePlatform()->getDefaultSchemaName();
     $primaryTableName = 'primary_table';
     $foreignTableName = 'foreign_table';
     $table = new Table($foreignTableName);
     $table->addColumn('id', 'integer', array('autoincrement' => true));
     $table->setPrimaryKey(array('id'));
     $this->_sm->dropAndCreateTable($table);
     $table = new Table($primaryTableName);
     $table->addColumn('id', 'integer', array('autoincrement' => true));
     $table->addColumn('foo', 'integer');
     $table->addColumn('bar', 'string');
     $table->addForeignKeyConstraint($foreignTableName, array('foo'), array('id'));
     $table->addIndex(array('bar'));
     $table->setPrimaryKey(array('id'));
     $this->_sm->dropAndCreateTable($table);
     $this->assertEquals($this->_sm->listTableColumns($primaryTableName), $this->_sm->listTableColumns($defaultSchemaName . '.' . $primaryTableName));
     $this->assertEquals($this->_sm->listTableIndexes($primaryTableName), $this->_sm->listTableIndexes($defaultSchemaName . '.' . $primaryTableName));
     $this->assertEquals($this->_sm->listTableForeignKeys($primaryTableName), $this->_sm->listTableForeignKeys($defaultSchemaName . '.' . $primaryTableName));
 }
开发者ID:selimcr,项目名称:servigases,代码行数:24,代码来源:SchemaManagerFunctionalTestCase.php

示例12: listTableForeignKeys

 /**
  * {@see AbstractSchemaManager::listTableForeignKeys}
  */
 public function listTableForeignKeys($table, $database = null)
 {
     return $this->manager->listTableForeignKeys($this->replacePrefix($table), $database);
 }
开发者ID:enyaku,项目名称:myGoogleMapsApiV3Test,代码行数:7,代码来源:Utility.php


注:本文中的Doctrine\DBAL\Schema\AbstractSchemaManager::listTableForeignKeys方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。