Skip to content

Commit

Permalink
Fixed an issue with unnecessary queries for one-to-one related objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
brunnels committed Oct 7, 2012
1 parent e66636c commit 35eb198
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions generator/lib/builder/om/PHP5ObjectBuilder.php
Expand Up @@ -3250,13 +3250,14 @@ protected function addFKAccessor(&$script, ForeignKey $fk)
* Get the associated $className object
*
* @param PropelPDO \$con Optional Connection object.
* @param \$doQuery Executes a query to get the object if required
* @return $className The associated $className object.
* @throws PropelException
*/
public function get".$this->getFKPhpNameAffix($fk, $plural = false)."(PropelPDO \$con = null)
{";
$script .= "
if (\$this->$varName === null && ($conditional)) {";
if (\$this->$varName === null && ($conditional) && \$doQuery) {";
if ($useRetrieveByPk) {
$script .= "
\$this->$varName = ".$fkQueryBuilder->getClassname()."::create()->findPk($localColumns, \$con);";
Expand Down Expand Up @@ -3952,7 +3953,7 @@ public function set".$this->getRefFKPhpNameAffix($refFK, $plural = false)."($cla
\$this->$varName = \$v;
// Make sure that that the passed-in $className isn't already associated with this object
if (\$v !== null && \$v->get".$this->getFKPhpNameAffix($refFK, $plural = false)."() === null) {
if (\$v !== null && \$v->get".$this->getFKPhpNameAffix($refFK, $plural = false)."(null, false) === null) {
\$v->set".$this->getFKPhpNameAffix($refFK, $plural = false)."(\$this);
}
Expand Down

0 comments on commit 35eb198

Please sign in to comment.