Re: DB_DataObject joinAdd - joining to a non DB_DataObject table

From: Date: Wed, 23 Feb 2005 06:37:26 +0000
Subject: Re: DB_DataObject joinAdd - joining to a non DB_DataObject table
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17641@lists.php.net to get a copy of this message
On Wed, 23 Feb 2005 17:16:38 +1100, Craig Ambrose <craigambrose@gmail.com> wrote: > > Hi Alan and other folks, > > I'm calling the DB_DataObject "joinAdd" function, passing through an > associative array for the $obj parameter. I'm trying to use this to join from > a table which does have a DB_DataObject defined, to one that doesn't (because > it is fairly dynamic in nature). > > (I'm using DB_DataObject v1.7.2 and PHP5.0.2) > > The result I get is that this works fine if there is a DB_DataObject table > file created for the table I'm joining to, but not if there isn't one. > > This code is commented as experimental, so I'm not expecting miracles. :) > However, I think I can see a problem with the code (presuming I'm correctly > interpreting it's goal) which I'll outline below. > > In your joinAdd function, the code in question looks like this: > > if (is_array($obj)) { > $tfield = $obj[0]; > list($toTable,$ofield) = explode(':',$obj[1]); > $obj = DB_DataObject::factory($toTable); > if (!$obj) { > $obj = new DB_DataObject; > $obj->__table = $toTable; > } > // set the table items to nothing.. - eg. do not try and match > // things in the child table...??? > $items = array(); > } > > In my case, it will be attempting to call DB_DataObject::factory with a table > name for which there is no DB_DataObject table definition, so the factory > will fail. The code above checks for this case, with "if (!$obj)". However, > if it fails, the factory function looks to be returning an new > DB_DataObject_Error object, rather than NULL. So the if condition above > doesn't get triggered, and instead this function tries to operate on the > error object as if it was a valid DB_DataObject, and dies with a fatal error > when it finds that it cannot. > > I'd love to see this code work. My rough guess is that if the factory returned > null, rather than an error. Or, if the code above checked for an error, > rather than just for NULL, things may well work as expected. > Well....try changing that if statement to do PEAR::isError on the return and see if it works. -- Justin Patrin

« previous php.pear.general (#17641) next »