本文整理汇总了PHP中Propel\Generator\Model\Table::getAutoIncrementPrimaryKey方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::getAutoIncrementPrimaryKey方法的具体用法?PHP Table::getAutoIncrementPrimaryKey怎么用?PHP Table::getAutoIncrementPrimaryKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Propel\Generator\Model\Table
的用法示例。
在下文中一共展示了Table::getAutoIncrementPrimaryKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPrimaryKeyDDL
/**
* Returns the SQL for the primary key of a Table object
*
* @param Table $table
*
* @return string
*/
public function getPrimaryKeyDDL(Table $table)
{
if ($table->hasPrimaryKey()) {
$keys = $table->getPrimaryKey();
//MySQL throws an 'Incorrect table definition; there can be only one auto column and it must be defined as a key'
//if the primary key consists of multiple columns and if the first is not the autoIncrement one. So
//this push the autoIncrement column to the first position if its not already.
$autoIncrement = $table->getAutoIncrementPrimaryKey();
if ($autoIncrement && $keys[0] != $autoIncrement) {
$idx = array_search($autoIncrement, $keys);
if ($idx !== false) {
unset($keys[$idx]);
array_unshift($keys, $autoIncrement);
}
}
return 'PRIMARY KEY (' . $this->getColumnListDDL($keys) . ')';
}
}
示例2: testGetAutoIncrementPrimaryKey
public function testGetAutoIncrementPrimaryKey()
{
$column1 = $this->getColumnMock('id', array('primary' => true, 'auto_increment' => true));
$column2 = $this->getColumnMock('title');
$column3 = $this->getColumnMock('isbn');
$table = new Table();
$table->setIdMethod('native');
$table->addColumn($column1);
$table->addColumn($column2);
$table->addColumn($column3);
$this->assertCount(1, $table->getPrimaryKey());
$this->assertTrue($table->hasPrimaryKey());
$this->assertTrue($table->hasAutoIncrementPrimaryKey());
$this->assertSame($column1, $table->getAutoIncrementPrimaryKey());
}