Re: Re: Choosing which column to use with DB_DataObject::joinAdd()
| From: | Phil Gyford | Date: | Thu, 30 Jun 2005 10:45:06 +0000 |
| Subject: | Re: Re: Choosing which column to use with DB_DataObject::joinAdd() | ||
| References: | 1 2 3 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-19840@lists.php.net to get a copy of this message | ||
[Just realised gmail hadn't been replying to all and I think I'd taken
this off-list by mistake. So in case anyone needs this and searches
the pear-general archive in future...]
Thanks so much James - that does the trick! I looked at the code, but
obviously missed the bit about the array.
One odd thing: although it says "If you use an array here it should be
in the format: array ('local_column','remotetable:remote_column');" -
I got an error if I used the actual name of the table and had to use
the name of the object instead. ie:
$friend->joinAdd(array('from_id', 'person:id'));
whereas the name of the table used for person data is 'projectname_person'.
Still, works a treat now - thanks!
On 6/29/05, James Stewart <lists@jystewart.net> wrote:
> On Jun 29, 2005, at 10:23 AM, Phil Gyford wrote:
> > On 6/29/05, James Stewart <lists@jystewart.net> wrote:
> >> how's about:
> >>
> >> global $_DB_DATAOBJECT;
> >> if ($direction == 'out') {
> >> $person->joinAdd(array('friend', 'from_id'));
> >> } else {
> >> $person->joinAdd(array('friend', 'to_id'));
> >> }
> >>
> >> I ran into a similar problem a few months ago, and I think this
> >> resolved it (but wasn't documented so I had to make a lot of use of
> >> this list and dig around in the source code).
> >>
> >
> >
> > I get errors with that I'm afraid:
> >
> > DataObjects_Person: ERROR: autoload:Could not find class
> > DataObjects_To_id using class_location value
> > DataObjects_Person: ERROR: factory could not find class from to_id
> >
> > The same if I use $friend instead of 'friend'.
>
> I should have checked my references before sending that. According to
> the DO source code, the first parameter to joinAdd can be an object
> or an array. If it's an object, it should be another DO. If it's an
> array then the format is:
>
> array('local_column','remotetable:remote_column');
>
> From the code:
>
> * @param optional $obj object |array the joining
> object (no value resets the join)
> * If you use an array
> here it should be in the format:
> * array
> ('local_column','remotetable:remote_column');
> * if remotetable does
> not have a definition, you should
> * use @ to hide the
> include error message..
> *
> *
> * @param optional $joinType string
> 'LEFT'|'INNER'|'RIGHT'|'' Inner is default,
> '' indicates
> * just select ... from
> a,b,c with no join and
> * links are added as
> where items.
> *
> * @param optional $joinAs string if you want to
> select the table as anther name
> * useful when you want
> to select multiple columsn
> * from a secondary table.
>
> * @param optional $joinCol string The column on This
> objects table to match (needed
> * if this table links
> to the child object in
> * multiple places eg.
> * user->friend (is a
> link to another user)
> * user->mother (is a
> link to another user..)
>
>
> hth.
>
> James.
> --
> James Stewart
> Play: http://james.anthropiccollective.org
> Work: http://jystewart.net
>
>
>
>