Skip to content

Commit

Permalink
Merge pull request #476 from marcj/master
Browse files Browse the repository at this point in the history
Bugfix for #473.
  • Loading branch information
Marc J. Schmidt committed Mar 18, 2014
2 parents 9742015 + e9e8b3d commit 06a4665
Show file tree
Hide file tree
Showing 36 changed files with 3,991 additions and 437 deletions.
70 changes: 70 additions & 0 deletions src/Propel/Generator/Builder/Om/AbstractOMBuilder.php
Expand Up @@ -16,6 +16,7 @@
use Propel\Generator\Exception\LogicException;
use Propel\Generator\Exception\RuntimeException;
use Propel\Generator\Model\Column;
use Propel\Generator\Model\CrossForeignKeys;
use Propel\Generator\Model\ForeignKey;

/**
Expand Down Expand Up @@ -590,6 +591,75 @@ public function getFKPhpNameAffix(ForeignKey $fk, $plural = false)
return $className . $this->getRelatedBySuffix($fk);
}

/**
* @param CrossForeignKeys $crossFKs
* @param bool $plural
* @return string
*/
protected function getCrossFKsPhpNameAffix(CrossForeignKeys $crossFKs, $plural = true)
{
$names = [];
foreach ($crossFKs->getCrossForeignKeys() as $fk) {
$names[] = $this->getFKPhpNameAffix($fk, false);
}

foreach ($crossFKs->getUnclassifiedPrimaryKeys() as $pk) {
$names[] = $pk->getPhpName();
}

$name = implode($names);
return (true === $plural ? $this->getPluralizer()->getPluralForm($name) : $name);
}

protected function getCrossFKInformation(CrossForeignKeys $crossFKs)
{
$names = [];
$signatures = [];
$shortSignature = [];
$phpDoc = [];

foreach ($crossFKs->getCrossForeignKeys() as $fk) {
$crossObjectName = '$' . lcfirst($this->getFKPhpNameAffix($fk)); //$fk->getForeignTable()->getStudlyPhpName();
$crossObjectClassName = $this->getNewObjectBuilder($fk->getForeignTable())->getObjectClassName();

$names[] = $crossObjectClassName;
$signatures[] = "$crossObjectClassName $crossObjectName" . ($fk->isAtLeastOneLocalColumnRequired() ? '' : ' = null');
$shortSignature[] = $crossObjectName;
$phpDoc[] = "
* @param $crossObjectClassName $crossObjectName The object to relate";
}

$names = implode(', ', $names). (1 < count($names) ? ' combination' : '');
$phpDoc = implode($phpDoc);
$signatures = implode(', ', $signatures);
$shortSignature = implode(', ', $shortSignature);

return [
$names,
$phpDoc,
$signatures,
$shortSignature
];
}

/**
* @param CrossForeignKeys $crossFKs
* @return string
*/
protected function getCrossFKsVarName(CrossForeignKeys $crossFKs)
{
return 'coll' . $this->getCrossFKsPhpNameAffix($crossFKs);
}

/**
* @param ForeignKey $crossFK
* @return string
*/
protected function getCrossFKVarName(ForeignKey $crossFK)
{
return 'coll' . $this->getFKPhpNameAffix($crossFK, true);
}

/**
* Gets the "RelatedBy*" suffix (if needed) that is attached to method and variable names.
*
Expand Down

0 comments on commit 06a4665

Please sign in to comment.