DB_DataObject joinAdd - joining to a non DB_DataObject table

From: Date: Wed, 23 Feb 2005 06:16:38 +0000
Subject: DB_DataObject joinAdd - joining to a non DB_DataObject table
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-17640@lists.php.net to get a copy of this message
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. regards, Craig -- Craig Ambrose Web Elements http://www.portallus.com/people/craigambrose/

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