/** * {@inheritdoc} */ public function create() { if ((!isset($this->options['id']) || $this->options['id'] === false) && !empty($this->primaryKey)) { $this->options['primary_key'] = $this->primaryKey; $this->filterPrimaryKey(); } parent::create(); }
public function testAddTableWithForeignKey() { $this->mock->expects($this->any())->method('isValidColumnType')->with($this->callback(function ($column) { return in_array($column->getType(), array('string', 'integer')); }))->will($this->returnValue(true)); $table = new Table('table', array(), $this->adapter); $table->addColumn('bar', 'string')->addColumn('relation', 'integer')->addForeignKey('relation', 'target_table', array('id')); $this->mock->expects($this->once())->method('createTable')->with($this->callback(function ($table) { if ($table->getName() !== 'pre_table_suf') { throw new \Exception(sprintf('Table::getName was not prefixed/suffixed properly: "%s"', $table->getName())); } $fks = $table->getForeignKeys(); if (count($fks) !== 1) { throw new \Exception(sprintf('Table::getForeignKeys count was incorrect: %d', count($fks))); } foreach ($fks as $fk) { if ($fk->getReferencedTable()->getName() !== 'pre_target_table_suf') { throw new \Exception(sprintf('ForeignKey::getReferencedTable was not prefixed/suffixed properly: "%s"', $fk->getReferencedTable->getName())); } } return true; })); $table->create(); }
/** * Creates a table from the object instance. * * @return mixed */ public function create() { $this->table->create(); return $this; }