Re: DB_DataObject - Table alias in joined query

From: Date: Tue, 22 Aug 2006 19:55:30 +0000
Subject: Re: DB_DataObject - Table alias in joined query
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-24959@lists.php.net to get a copy of this message
On 8/22/06, arnaud sellenet <demental@free.fr> wrote:
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'); ?>
Look at the API docs for joinAdd(). IIRC it has an option for the alias. -- Justin Patrin

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