Versionable behaviour mishandles 1:1 relationships. #451

Open
Fartlek opened this Issue Aug 17, 2012 · 3 comments

4 participants

@Fartlek

When creating a 1:1 relationship using the guide at http://www.propelorm.org/documentation/04-relationships.html#onetoone_relationships and if both tables are versionable, then the addVersion function in BookstoreEmployee will get the condition

if ($relateds = $this->getBookstoreEmployeeAccounts()->toKeyValue('EmployeeId', 'Version')) {
...
}

BookstoreEmployee has no such method getBookstoreEmployeeAccounts(), so calling save() on a BookstoreEmployee will throw a Call to undefined method: getBookstoreEmployeeAccounts error.

The problem stems from VersionableBehaviorObjectBuilderModifier.php's addAddVersion method where

foreach ($this->behavior->getVersionableReferrers() as $fk) {
    $fkGetter = $this->builder->getRefFKPhpNameAffix($fk, $plural = true);
    $idsColumn = $this->behavior->getReferrerIdsColumn($fk);
    $versionsColumn = $this->behavior->getReferrerVersionsColumn($fk);
    $script .= "
if (\$relateds = \$this->get{$fkGetter}(\$con)->toKeyValue('{$fk->getTable()->getFirstPrimaryKeyColumn()->getPhpName()}', 'Version')) {
    \$version->set{$idsColumn->getPhpName()}(array_keys(\$relateds));
    \$version->set{$versionsColumn->getPhpName()}(array_values(\$relateds));
}";
}

is assuming that all versionable referrers are part of a many (*) relationship and so everything is plural.

The BookstoreEmployeeVersion class also has plural references to the BookstoreEmployeeAccount.

@mrackwitz

Just mentioned this bug yesterday by myself, too. I wrote a working bugfix, which I would pull request soon.

@willdurand
Propel member

@mrackwitz time to pull request?

@havvg
Propel member

Hi, @mrackwitz you got the PR?
I just encountered the error, too. Please send the PR, if it's working :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment