Ticket #463 (closed defect: fixed)
doSelectJoin* peer methods try calling non-existent add methods on one-to-one related objects
| Reported by: | threeoftwelve@… | Owned by: | hans |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | Generator | Version: | 1.3.0beta2 |
| Severity: | normal | Keywords: | doSelectJoin one-to-one add set |
| Cc: |
Description
I ran into this problem when I tried to call Foo::getBarJoinQuux() with one-to-one related Bar and Quux tables. The function calls BarPeer::doSelectJoinQuux(), which in turn tries to add the Bar object to Foo's collection of related Bar objects. However, since they are one-to-one related, there is no such collection and no Foo::addBar() method, but a Foo::setBar() method instead.
I got it to work using the following patch to current SVN HEAD (though running 1.3beta2 off SVN):
181,182c181,190
< // Add the \$obj1 (".$this->getObjectClassname().") to the collection in \$obj2 (".$joinedTablePeerBuilder->getObjectClassname().")
< \$obj2->add".$joinedTableObjectBuilder->getRefFKPhpNameAffix($fk, $plural = false)."(\$obj1);
---
> ";
> if ($fk->isLocalPrimaryKey()) {
> $script .= " // Set \$obj1 (".$this->getObjectClassname().") as one-to-one related in \$obj2 (".$joinedTablePeerBuilder->getObjectClassname().")
> \$obj2->set".$joinedTableObjectBuilder->getRefFKPhpNameAffix($fk, $plural = false)."(\$obj1);";
> } else {
> $script .= " // Add the \$obj1 (".$this->getObjectClassname().") to the collection in \$obj2 (".$joinedTablePeerBuilder->getObjectClassname().")
> \$obj2->add".$joinedTableObjectBuilder->getRefFKPhpNameAffix($fk, $plural = false)."(\$obj1);";
> } // if fk->isLocalPrimaryKey
>
> $script .= "
Change History
Note: See
TracTickets for help on using
tickets.
I forgot to mention that the patch is for propel.engine.builder.om.php5.PHP5ComplexObjectBuilder.php.