Fwd: [PEAR] getLinks from an M-N jointure : multiple records ?

From: Date: Tue, 19 Jul 2005 13:13:44 +0000
Subject: Fwd: [PEAR] getLinks from an M-N jointure : multiple records ?
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-20055@lists.php.net to get a copy of this message
Oups. This code works... almost (I tried with both first and second example). I get the right number of lines (corresponding to the right number of groups) but, they are empty... it seems that it doesn't find $group->name in the first case, $group_connect->name in the second case. just to be sure, if my fields are PERSON.name and GROUP.name, which "name" do you speak about ? (to me it is GROUP.name). Thank for your help... David -----Message d'origine----- De : Justin Patrin [mailto:papercrane@gmail.com] Envoyé : lundi 18 juillet 2005 18:52 À : David Alia Cc : pear-general@lists.php.net Objet : Re: [PEAR] getLinks from an M-N jointure : multiple records ? [snip] This is what is called a crossLink in the DB_DataObject_FormBuilder package. There is no way in DB_DataObject to get these connections with a single funciton call like getLink. However this is still very easy. I'm actually very surprised at how often this question seems to be asked... $person =& DB_DataObject::factory('person'); $person->get(13); $group_connect =& DB_DataObject::factory('persgroup'); $group_connect->personID = $person->ID; if ($group_connect->find()) { while ($group_connect->fetch()) { $group =& $group_connect->getLink('groupID'); echo $group->name.'<br/>'; } } Or alternatively, you can use joinAdd to reduce your queries: $person =& DB_DataObject::factory('person'); $person->get(13); $group_connect =& DB_DataObject::factory('persgroup'); $group_connect->personID = $person->ID; $group =& DB_DataObject::factory('group'); $group_connect->joinAdd($group); if ($group_connect->find()) { while ($group_connect->fetch()) { echo $group_connect->name.'<br/>'; } } Or even further: $group_connect =& DB_DataObject::factory('persgroup'); $person =& DB_DataObject::factory('person'); $person->ID = 13; $group_connect->joinAdd($person); $group =& DB_DataObject::factory('group'); $group_connect->joinAdd($group); $group_connect->selectAdd(); //technically these should be quoted with DB::quoteIdentifier() $group_connect->selectAdd('group.name'); if ($group_connect->find()) { while ($group_connect->fetch()) { echo $group_connect->name.'<br/>'; } }

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