本文整理汇总了PHP中ForeignKey::setName方法的典型用法代码示例。如果您正苦于以下问题:PHP ForeignKey::setName方法的具体用法?PHP ForeignKey::setName怎么用?PHP ForeignKey::setName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ForeignKey
的用法示例。
在下文中一共展示了ForeignKey::setName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: modifyTable
public function modifyTable()
{
$parentTable = $this->getParentTable();
if (count($parentTable->getPrimaryKey()) > 1) {
throw new RuntimeException('Equal nest works only with a single primary key for the parent table');
}
$parentTablePrimaryKey = $parentTable->getPrimaryKey();
if (!$this->getTable()->hasColumn($this->getReferenceColumn1Name())) {
$this->getTable()->addColumn(array('name' => $this->getReferenceColumn1Name(), 'primaryKey' => 'true', 'type' => $parentTablePrimaryKey[0]->getType()));
$fk = new ForeignKey();
$fk->setName($this->getReferenceColumn1Name());
$fk->setForeignTableCommonName($this->getParentTable()->getCommonName());
$fk->setOnDelete(ForeignKey::CASCADE);
$fk->setOnUpdate(null);
$fk->addReference($this->getReferenceColumn1Name(), $parentTablePrimaryKey[0]->getName());
$this->getTable()->addForeignKey($fk);
}
if (!$this->getTable()->hasColumn($this->getReferenceColumn2Name())) {
$this->getTable()->addColumn(array('name' => $this->getReferenceColumn2Name(), 'primaryKey' => 'true', 'type' => $parentTablePrimaryKey[0]->getType()));
$fk = new ForeignKey();
$fk->setName($this->getReferenceColumn2Name());
$fk->setForeignTableCommonName($this->getParentTable()->getCommonName());
$fk->setOnDelete(ForeignKey::CASCADE);
$fk->setOnUpdate(null);
$fk->addReference($this->getReferenceColumn2Name(), $parentTablePrimaryKey[0]->getName());
$this->getTable()->addForeignKey($fk);
}
if (!$parentTable->hasBehavior('equal_nest_parent')) {
$parentBehavior = new EqualNestParentBehavior();
$parentBehavior->setName('equal_nest_parent');
$parentBehavior->addParameter(array('name' => 'middle_table', 'value' => $this->getTable()->getName()));
$parentTable->addBehavior($parentBehavior);
}
$this->parentBehavior = $parentTable->getBehavior('equal_nest_parent');
}
示例2: testColumnIsFKAndPK
public function testColumnIsFKAndPK()
{
$column = new Column();
$column->setName('id');
$column->setPrimaryKey(true);
$column->setAutoIncrement(true);
$column->setType('integer');
$table = new Table();
$table->setCommonName('table_one');
$table->addColumn($column);
$db = new Database();
$db->setName('MultipleTables');
$db->addTable($table);
$column = new Column();
$column->setName('id');
$column->setPrimaryKey(true);
$column->setAutoIncrement(true);
$column->setType('integer');
$c2 = new Column();
$c2->setPrimaryKey(true);
$c2->setName('foreign_id');
$c2->setType('integer');
$table = new Table();
$table->setCommonName('table_two');
$table->addColumn($column);
$table->addColumn($c2);
$fk = new ForeignKey();
$fk->setName('FK_1');
$fk->addReference('foreign_id', 'id');
$fk->setForeignTableCommonName('table_one');
$table->addForeignKey($fk);
$db->addTable($table);
$expected = implode("\n", array('digraph G {', 'nodetable_one [label="{<table>table_one|<cols>id (integer) [PK]\\l}", shape=record];', 'nodetable_two [label="{<table>table_two|<cols>id (integer) [PK]\\lforeign_id (integer) [FK] [PK]\\l}", shape=record];', 'nodetable_two:cols -> nodetable_one:table [label="foreign_id=id"];', '}', ''));
$this->assertEquals($expected, PropelDotGenerator::create($db));
}