/** * Appends the generated <foreign-key> XML node to its parent node. * * @param ForeignKey $foreignKey The ForeignKey model instance * @param \DOMNode $parentNode The parent DOMNode object */ private function appendForeignKeyNode(ForeignKey $foreignKey, \DOMNode $parentNode) { $foreignKeyNode = $parentNode->appendChild($this->document->createElement('foreign-key')); $foreignKeyNode->setAttribute('foreignTable', $foreignKey->getForeignTableCommonName()); if ($schema = $foreignKey->getForeignSchemaName()) { $foreignKeyNode->setAttribute('foreignSchema', $schema); } $foreignKeyNode->setAttribute('name', $foreignKey->getName()); if ($phpName = $foreignKey->getPhpName()) { $foreignKeyNode->setAttribute('phpName', $phpName); } if ($refPhpName = $foreignKey->getRefPhpName()) { $foreignKeyNode->setAttribute('refPhpName', $refPhpName); } if ($defaultJoin = $foreignKey->getDefaultJoin()) { $foreignKeyNode->setAttribute('defaultJoin', $defaultJoin); } if ($onDeleteBehavior = $foreignKey->getOnDelete()) { $foreignKeyNode->setAttribute('onDelete', $onDeleteBehavior); } if ($onUpdateBehavior = $foreignKey->getOnUpdate()) { $foreignKeyNode->setAttribute('onUpdate', $onUpdateBehavior); } for ($i = 0, $size = count($foreignKey->getLocalColumns()); $i < $size; $i++) { $refNode = $foreignKeyNode->appendChild($this->document->createElement('reference')); $refNode->setAttribute('local', $foreignKey->getLocalColumnName($i)); $refNode->setAttribute('foreign', $foreignKey->getForeignColumnName($i)); } foreach ($foreignKey->getVendorInformation() as $vendorInformation) { $this->appendVendorInformationNode($vendorInformation, $foreignKeyNode); } }
/** * Gets the PHP method name affix to be used for fkeys for the current table (not referrers to this table). * * The difference between this method and the getRefFKPhpNameAffix() method is that in this method the * classname in the affix is the foreign table classname. * * @param ForeignKey $fk The local FK that we need a name for. * @param boolean $plural Whether the php name should be plural (e.g. initRelatedObjs() vs. addRelatedObj() * @return string */ public function getFKPhpNameAffix(ForeignKey $fk, $plural = false) { if ($fk->getPhpName()) { if ($plural) { return $this->getPluralizer()->getPluralForm($fk->getPhpName()); } return $fk->getPhpName(); } $className = $fk->getForeignTable()->getPhpName(); if ($plural) { $className = $this->getPluralizer()->getPluralForm($className); } return $className . $this->getRelatedBySuffix($fk); }
public function testSetNames() { $fk = new ForeignKey(); $fk->setName('book_author'); $fk->setPhpName('Author'); $fk->setRefPhpName('Books'); $this->assertSame('book_author', $fk->getName()); $this->assertSame('Author', $fk->getPhpName()); $this->assertSame('Books', $fk->getRefPhpName()); }