DB_DataObject - Table alias in joined query

From: Date: Tue, 22 Aug 2006 11:59:23 +0000
Subject: DB_DataObject - Table alias in joined query
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-24954@lists.php.net to get a copy of this message
Hi. I have a problem making a joined query using DB_DataObject to the table itself (tree structure). This is the php code to build the query : <?php $cat = & DB_DataObject::factory('ent_category'); $fcat = & DB_DataObject::factory('ent_category'); $cat->joinAdd($fcat); $cat->selectAs($fcat,'ent_category__%s'); ?> This is the resulting SQL : SELECT count(ent_category.id) as DATAOBJECT_NUM FROM ent_category INNER JOIN project.ent_category ON ent_category.category_id=project.ent_category.id Which makes a SQL error. And this is the query that would work : SELECT count(e1.id) as DATAOBJECT_NUM FROM ent_category e1 INNER JOIN project.ent_category ON e1.category_id=project.ent_category.id In my mind I would have written something like this : <?php $cat = & DB_DataObject::factory('ent_category'); $cat->setAlias('e1'); $fcat = & DB_DataObject::factory('ent_category'); $cat->joinAdd($fcat); $cat->selectAs($fcat,'ent_category__%s'); ?>

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