Development

#3368 ([PATCH] nahoPropelOptimizerPlugin: NULLs-hydrated object test cause error in certain case)

You must first sign up to be able to contribute.

Ticket #3368 (closed enhancement: fixed)

Opened 3 months ago

Last modified 2 months ago

[PATCH] nahoPropelOptimizerPlugin: NULLs-hydrated object test cause error in certain case

Reported by: gilles.doge Assigned to: naholyr
Priority: minor Milestone:
Component: plugins Version:
Keywords: nahoPropelOptimizerPlugin plugins propel Cc:
Qualification: Unreviewed

Description

In the case that you have a NULL foreign key and don't use a LEFT JOIN (the related object is not already hydrated), the following generated test throw a PHP error:

// test in a related object accessor in a Propel BaseXXX.php
if (!$this->aObject->isNew() && is_null($this->aObject->getPrimaryKey())) {
   return NULL;
}

The problem is that in this case the $this->aObject attribute is null.

I attached a quick'n'dirty patch to transform the test in:

// test in a related object accessor in a Propel BaseXXX.php
if (!is_null($this->aObject) && !$this->aObject->isNew() && is_null($this->aObject->getPrimaryKey())) {
   return NULL;
}

But I think it would be better to handle the "NULLs-hydrated object" problem in doSelectJoinXXX methods, no ?

Attachments

SfOptimizedObjectBuilder.php.patch (0.6 kB) - added by gilles.doge on 04/19/08 13:26:13.
Patch to SfOptimizedObjectBuilder?.php

Change History

04/19/08 13:26:13 changed by gilles.doge

  • attachment SfOptimizedObjectBuilder.php.patch added.

04/21/08 15:22:33 changed by naholyr

  • status changed from new to closed.
  • resolution set to fixed.

Applied your attached patch, its seems to be enough to fix the issue.

Changes commited to SVN.

I prefer handling this in the FKAccessor because I'm sure not to forget any case ;)

05/14/08 19:49:35 changed by tripollite

  • type changed from defect to enhancement.

I correct this error with that :

      foreach ($this->getTable()->getColumns() as $column) {
        if ($column->isForeignKey()) 
		{
          $colName = substr($column->getPhpName(),2);
		  $from = '#\$temp_obj([2-9]+) = \$temp_obj1->get' . ucfirst($colName) . '\(\)\;#SUmis';
          if ( !$column->isNotNull() ) 
		  {
			  $to = '
			  if($temp_obj1->getId'.ucfirst($colName).'() !== NULL) 
			  	$temp_obj$1 = $temp_obj1->get' . ucfirst($colName) . '(); 
			  else
			  	$temp_obj$1 = new '.ucfirst($colName).';
			  ';
			  $peerCode = preg_replace($from, $to, $peerCode);
          }
        }
      }