Ticket #463 (closed defect: fixed)

Opened 3 years ago

Last modified 3 years ago

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

comment:1 Changed 3 years ago by threeoftwelve@…

I forgot to mention that the patch is for propel.engine.builder.om.php5.PHP5ComplexObjectBuilder.php.

comment:2 Changed 3 years ago by hans

  • Status changed from new to closed
  • Resolution set to fixed

This should be fixed as of changeset:830 (as part of a fix for #464).

Note: See TracTickets for help on using tickets.