Re: writing Joins using DB_DataObject 1.7.10
| From: | Justin Patrin | Date: | Sun, 20 Mar 2005 04:23:59 +0000 |
| Subject: | Re: writing Joins using DB_DataObject 1.7.10 | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-18159@lists.php.net to get a copy of this message | ||
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"..
LEFT is the same as LEFT OUTER.
>
> 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.
--
Justin Patrin