Example #1
0
 public function testProxyAdapterCanInvertAddForeignKey()
 {
     $table = new \Phinx\Db\Table('atable');
     $refTable = new \Phinx\Db\Table('refTable');
     $fk = new \Phinx\Db\Table\ForeignKey();
     $fk->setReferencedTable($refTable)->setColumns(array('ref_table_id'))->setReferencedColumns(array('id'));
     $this->adapter->addForeignKey($table, $fk);
     $commands = $this->adapter->getInvertedCommands();
     $this->assertEquals('dropForeignKey', $commands[0]['name']);
     $this->assertEquals('atable', $commands[0]['arguments'][0]);
     $this->assertContains('ref_table_id', $commands[0]['arguments'][1]);
 }
Example #2
0
 /**
  * Add a foreign key to a database table.
  *
  * In $options you can specify on_delete|on_delete = cascade|no_action ..,
  * on_update, constraint = constraint name.
  *
  * @param string|array $columns Columns
  * @param string|Table $referencedTable   Referenced Table
  * @param string|array $referencedColumns Referenced Columns
  * @param array $options Options
  * @return Table
  */
 public function addForeignKey($columns, $referencedTable, $referencedColumns = array('id'), $options = array())
 {
     if (is_string($referencedColumns)) {
         $referencedColumns = array($referencedColumns);
         // str to array
     }
     $fk = new ForeignKey();
     if ($referencedTable instanceof Table) {
         $fk->setReferencedTable($referencedTable);
     } else {
         $fk->setReferencedTable(new Table($referencedTable, array(), $this->adapter));
     }
     $fk->setColumns($columns)->setReferencedColumns($referencedColumns)->setOptions($options);
     $this->foreignKeys[] = $fk;
     return $this;
 }
 /**
  * Sets the foreign key referenced table.
  *
  * @param TableMigrationInterface $table
  *
  * @return $this
  */
 public function setReferencedTable(TableMigrationInterface $table)
 {
     $this->foreign->setReferencedTable($table);
     return $this;
 }