本文整理汇总了PHP中Doctrine\DBAL\Schema\AbstractSchemaManager::createForeignKey方法的典型用法代码示例。如果您正苦于以下问题:PHP AbstractSchemaManager::createForeignKey方法的具体用法?PHP AbstractSchemaManager::createForeignKey怎么用?PHP AbstractSchemaManager::createForeignKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Schema\AbstractSchemaManager
的用法示例。
在下文中一共展示了AbstractSchemaManager::createForeignKey方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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'));
}
}
示例2: 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()));
}
示例3: createForeignKey
/**
* {@see AbstractSchemaManager::createForeignKey}
*/
public function createForeignKey(ForeignKeyConstraint $foreignKey, $table)
{
$this->manager->createForeignKey($foreignKey, $this->replacePrefix($table));
}