For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > June 2004 > DB_DataObject joinAdd









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author DB_DataObject joinAdd
Daniel Kopp

2004-06-16, 3:57 pm

Hi!

Excited I found out that DB_DataObject's joinAdd supports a
defineable column now. But - I cannot understand why I cannot do
whatever I want with it. I keep getting a

"You cannot target a join column in the 'link from' table
(kia_seminaranmeldung). Either remove the fourth argument to joinAdd
() ((ad2.pID=semanm.pID)), or alter your links.ini file."

That is not really a help but rather very annoying as it will
probably force me to use a raw query once more (which is un as I
cannot configure that optionally as good as a real DB_DataObject
query)

I do this:

$ad2->joinAdd($semanm2, 'LEFT','semanm2','(ad2.pID=semanm2.pID)');
$verb->joinAdd($ad2, 'LEFT', 'ad2');
$fidpid->joinAdd($verb, 'LEFT');
$ad->joinAdd($fidpid, 'LEFT');
$semanm->joinAdd($ad);

which is supposed to Link semanm2 to ad2 but instead semanm is linked
to ad (which is the same table that is used twice in the query - the
second time renamed to ad2)

I would like to get:

SELECT foo, bar, baz
FROM kia_seminaranmeldung
INNER JOIN kia_adressen ON kia_adressen.pID =
kia_seminaranmeldung.pID
LEFT JOIN kia_fidpid ON kia_fidpid.pID = kia_adressen.pID
LEFT JOIN kia_familienverband ON kia_familienverband.fID =
kia_fidpid.fID
LEFT JOIN kia_adressen AS ad2 ON ad2.pID = kia_familienverband.pID
LEFT JOIN kia_seminaranmeldung sem2 ON ( ad2.pID = sem2.pID AND
sem2.sID =
kia_seminaranmeldung.sID )

I know that looks strange but it gives me the right result ... and
you haven't seen the where statement :-)

How can I tell DB_DataObject to either link the table properly or use
a real custom column? Of course semanm2 and ad2 have a link entry in
my database.ini ... Maybe the renameing of the tables confuses the
object ...

regards
Daniel
Daniel Kopp

2004-06-16, 3:57 pm

Hi!

I wonder whether it helps to use tableName but if I rename a table-
Object with this I always get a

dataobject_kia_adressen: ERROR: joinAdd: semanm2 has no link with ad2

I even tried to add links for this renamed tables in my links.ini which
did not help anything ...

regards
Daniel
Alan Knowles

2004-06-16, 3:57 pm

I'll have a look tommorow - I hardly ever use much more that the first
two options usually..

Regards
Alan

Daniel Kopp wrote:
> Hi!
>
> I wonder whether it helps to use tableName but if I rename a table-
> Object with this I always get a
>
> dataobject_kia_adressen: ERROR: joinAdd: semanm2 has no link with ad2
>
> I even tried to add links for this renamed tables in my links.ini which
> did not help anything ...
>
> regards
> Daniel

Daniel Kopp

2004-06-16, 8:56 pm

Hi!

Alan Knowles wrote:

> I'll have a look tommorow - I hardly ever use much more that the
> first two options usually..


me not either :-) I did not know about them until today as they were
not in my docu :-)
The docu however does not really tell how they are supposed to be
written (i. e. there is no example ...)

Thanks
Daniel
Alan Knowles

2004-06-18, 8:56 am

Finally got a chance to go through the code for joinAdd, and try and
understand this a bit.

The forth argument to joinAdd is related to muliply joining a single
table into another:

[user]
;id
friend = person:id
mother = person:id


$person->joinAdd($user,'LEFT',false,'friend');
should generate something like:
person LEFT JOIN user ON person.id = user.friend

It looks like you where trying to use the joinAdd argument to insert
into the query..

To be honest the best way to do what you are trying is probably defining
a method of the extended class:
function joinAddSeman()
$this->_joinAdd .= '...............';
}

Regards
Alan





Daniel Kopp wrote:
> Hi!
>
> Excited I found out that DB_DataObject's joinAdd supports a
> defineable column now. But - I cannot understand why I cannot do
> whatever I want with it. I keep getting a
>
> "You cannot target a join column in the 'link from' table
> (kia_seminaranmeldung). Either remove the fourth argument to joinAdd
> () ((ad2.pID=semanm.pID)), or alter your links.ini file."
>
> That is not really a help but rather very annoying as it will
> probably force me to use a raw query once more (which is un as I
> cannot configure that optionally as good as a real DB_DataObject
> query)
>
> I do this:
>
> $ad2->joinAdd($semanm2, 'LEFT','semanm2','(ad2.pID=semanm2.pID)');
> $verb->joinAdd($ad2, 'LEFT', 'ad2');
> $fidpid->joinAdd($verb, 'LEFT');
> $ad->joinAdd($fidpid, 'LEFT');
> $semanm->joinAdd($ad);
>
> which is supposed to Link semanm2 to ad2 but instead semanm is linked
> to ad (which is the same table that is used twice in the query - the
> second time renamed to ad2)
>
> I would like to get:
>
> SELECT foo, bar, baz
> FROM kia_seminaranmeldung
> INNER JOIN kia_adressen ON kia_adressen.pID =
> kia_seminaranmeldung.pID
> LEFT JOIN kia_fidpid ON kia_fidpid.pID = kia_adressen.pID
> LEFT JOIN kia_familienverband ON kia_familienverband.fID =
> kia_fidpid.fID
> LEFT JOIN kia_adressen AS ad2 ON ad2.pID = kia_familienverband.pID
> LEFT JOIN kia_seminaranmeldung sem2 ON ( ad2.pID = sem2.pID AND
> sem2.sID =
> kia_seminaranmeldung.sID )
>
> I know that looks strange but it gives me the right result ... and
> you haven't seen the where statement :-)
>
> How can I tell DB_DataObject to either link the table properly or use
> a real custom column? Of course semanm2 and ad2 have a link entry in
> my database.ini ... Maybe the renameing of the tables confuses the
> object ...
>
> regards
> Daniel



--
Can you help out?
Need Consulting Services or Know of a Job?
http://www.akbkhome.com
Daniel Kopp

2004-06-24, 1:22 am

Hi!

Thanks!

Alan Knowles wrote:

> It looks like you where trying to use the joinAdd argument to
> insert into the query..


well - yes - is that a crime? :-)

> To be honest the best way to do what you are trying is probably
> defining a method of the extended class:
> function joinAddSeman()
> $this->_joinAdd .= '...............';
> }
>


well - I think in this case I even dare to do the following:

$obj->_join.=' LEFT JOIN kia_seminaranmeldung semanm2 ON
semanm2.pID=ad2.pID ';

which seems to work even though I am pretty sure it will break in
php5 (there is protected mode for object-properties in php5 isn't
it?)

and ... for sure - this is a crime :-)

regards
Daniel
Alan Knowles

2004-06-24, 1:22 am

Daniel Kopp wrote:
> Hi!
>
> Thanks!
>
> Alan Knowles wrote:
>
>
> well - yes - is that a crime? :-)

Not really :) - but the parameter checking that there is will probably
cause problems


> which seems to work even though I am pretty sure it will break in
> php5 (there is protected mode for object-properties in php5 isn't
> it?)


DataObjects is a little odd in some respects, all the public (eg. non
_prefixed vars) are assumed to be available to be used as column names)
- so all other variables end up with _underscores, even though their
protection level may be public as well..

Regards
Alan

>
> and ... for sure - this is a crime :-)
>
> regards
> Daniel

Alan Knowles

2004-06-24, 1:22 am

Daniel Kopp wrote:
> Hi!
>
> Thanks!
>
> Alan Knowles wrote:
>
>
> well - yes - is that a crime? :-)

Not really :) - but the parameter checking that there is will probably
cause problems


> which seems to work even though I am pretty sure it will break in
> php5 (there is protected mode for object-properties in php5 isn't
> it?)


DataObjects is a little odd in some respects, all the public (eg. non
_prefixed vars) are assumed to be available to be used as column names)
- so all other variables end up with _underscores, even though their
protection level may be public as well..

Regards
Alan

>
> and ... for sure - this is a crime :-)
>
> regards
> Daniel

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com