Choosing which column to use with DB_DataObject::joinAdd()

From: Date: Tue, 28 Jun 2005 18:34:55 +0000
Subject: Choosing which column to use with DB_DataObject::joinAdd()
Groups: php.pear.general 
Request: Send a blank email to pear-general+get-19810@lists.php.net to get a copy of this message
I'm having a problem using DB_DataObject's joinAdd(), with a table that has two ways of joining another. I think what I want to do is possible, but I can't understand either the joinAdd() documentation or the error message. I have a table (person) representing a person: id name And a table (friend) representing one-way relationships between those people: id from_id to_id My databasename.links.ini file has this: [person] id = friend.from_id id = friend.to_id [friend] from_id = person.id to_id = person.id I then have a getFriends() function. I can pass this a person_id and a 'direction', either 'in' or 'out. This will return either a list of people who call this person a friend ('in') or people who this person calls a friend ('out'): function getFriends ($person_id, $direction) { $person =& DB_DataObject::factory('person'); $friend =& DB_DataObject::factory('friend'); if ($direction == 'out') { $friend->from_id = $person_id; $person->joinAdd($friend); // Should join on friend.to_id=person.id } else { $friend->to_id = $person_id; $person->joinAdd($friend); // Should join on friend.from_id=person.id } // [Code for finding and returning the results in an array here] } Obviously, DB_DataObject can't magically know whether to join on from_id or to_id, so it only tries one way. I've tried doing things with the fourth argument one can pass to joinAdd() but don't understand the docs and always get this error: "joinAdd: You cannot target a join column in the 'link from' table (dvb_friend). Either remove the fourth argument to joinAdd() (from_id), or alter your links.ini file." I don't understand this either... Can anyone help me set which column to join with? Many thanks. Phil

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