public function getForeignKeyDDL(ForeignKey $fk) { if ($fk->isSkipSql() || $fk->isPolymorphic()) { return; } $pattern = 'CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)'; $script = sprintf($pattern, $this->quoteIdentifier($fk->getName()), $this->getColumnListDDL($fk->getLocalColumnObjects()), $this->quoteIdentifier($fk->getForeignTableName()), $this->getColumnListDDL($fk->getForeignColumnObjects())); if ($fk->hasOnUpdate() && $fk->getOnUpdate() != ForeignKey::SETNULL) { $script .= ' ON UPDATE ' . $fk->getOnUpdate(); } if ($fk->hasOnDelete() && $fk->getOnDelete() != ForeignKey::SETNULL) { $script .= ' ON DELETE ' . $fk->getOnDelete(); } return $script; }
public function testGetLocalColumn() { $column = $this->getColumnMock('id'); $table = $this->getTableMock('books'); $table->expects($this->any())->method('getColumn')->with($this->equalTo('author_id'))->will($this->returnValue($column)); $fk = new ForeignKey(); $fk->setTable($table); $fk->addReference('author_id', 'id'); $this->assertCount(1, $fk->getLocalColumnObjects()); $this->assertInstanceOf('Propel\\Generator\\Model\\Column', $fk->getLocalColumn(0)); }
public function getForeignKeyDDL(ForeignKey $fk) { if ($fk->isSkipSql() || $fk->isPolymorphic()) { return; } $pattern = "CONSTRAINT %s\n FOREIGN KEY (%s) REFERENCES %s (%s)"; $script = sprintf($pattern, $this->quoteIdentifier($fk->getName()), $this->getColumnListDDL($fk->getLocalColumnObjects()), $this->quoteIdentifier($fk->getForeignTableName()), $this->getColumnListDDL($fk->getForeignColumnObjects())); if ($fk->hasOnDelete()) { $script .= "\n ON DELETE " . $fk->getOnDelete(); } return $script; }
public function getForeignKeyDDL(ForeignKey $fk) { if ($fk->isSkipSql() || !$this->foreignKeySupport) { return; } $pattern = "FOREIGN KEY (%s) REFERENCES %s (%s)"; $script = sprintf($pattern, $this->getColumnListDDL($fk->getLocalColumnObjects()), $this->quoteIdentifier($fk->getForeignTableName()), $this->getColumnListDDL($fk->getForeignColumnObjects())); if ($fk->hasOnUpdate()) { $script .= "\n ON UPDATE " . $fk->getOnUpdate(); } if ($fk->hasOnDelete()) { $script .= "\n ON DELETE " . $fk->getOnDelete(); } return $script; }