Re: writing Joins using DB_DataObject 1.7.10
| From: | Kurund Jalmi | Date: | Mon, 21 Mar 2005 11:18:13 +0000 |
| Subject: | Re: writing Joins using DB_DataObject 1.7.10 | ||
| References: | 1 2 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-18194@lists.php.net to get a copy of this message | ||
Thanks all,
"LEFT" worked fine for me.. (instead of LEFT OUTER JOIN)
BUT still have problem writing multiple condition for "addJoin"
i have 3 tables
main, location and place
i created object for those three tables..
i did the following things.
$location->joinAdd($place);
$location->whereAdd($this->tableName().'.id = 1');
$main->joinAdd($location);
$main->whereAdd($main->tableName().'.id = '.$location->tableName().'.id');
after firing the sql..
when i checked my logs i found that.. condition for 'ON' clause was in
'WHERE' clause
it doesnnot adds to 'ON' clause of that join..
regards
kurund jalmi
Justin Patrin wrote:
LEFT is the same as LEFT OUTER.On Sat, 19 Mar 2005 19:39:39 +0530, Kurund Jalmi <kurund@webaccess.co.in> wrote:hello, i am working on DB_DataObject 1.7.10. i have few querries on writing joins: 1. How can i write "left outer joins" using DB_DataObjects? i found out that addjoin has only 3 options "LEFT, RIGHT AND INNER"..
2. If i want to write condition in ON clause of JOIN, i use the follwing method: $this->joinAdd($location); $this->whereAdd($this->id = $location->id); this works fine.I doubt it, that's not the right syntax at all. This should work: $this->whereAdd($this->tableName().'.id = '.$location->tableName().'.id');
but if i want to write multiple condition in ON clause for example: $this->joinAdd($location); $this->whereAdd($this->id = $location->id AND $location->state = 1); then only first condition is considered.. second is ignored..Again, probably because that's not the right syntax at all. $this->whereAdd($this->tableName().'.id = '.$location->tableName().'.id AND '.$location->tableName().'.state = 1'); Of course, adding a where isn't quite the same as actually adding to an on clause, especially when the join is OUTER. If you actually want to add to the ON clause you'll have to edit $this->_join manually. This is somewhat hard to do, though, especially if you're doing multiple joins.