Re: Dataobject : complex jointures

From: Date: Fri, 29 Jul 2005 02:18:28 +0000
Subject: Re: Dataobject : complex jointures
References: 1  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-20182@lists.php.net to get a copy of this message
Im sure there used to be a note in the manual that went something like this: "Although you can use DataObject to create complex joins, you may find that hard coding the JOIN part manually may actually be simpler to maintain and understand" It may be that using $do = DB_DataObject::factory(...) $do->selectAs('xx_%s'); $do->selectAs(DB_DataObject::factory(...), 'yy_%s'); $do->selectAs(DB_DataObject::factory(...), 'zz_%s'); $do->query('SELECT '. $do->selectAdd() . ' FROM ... LEFT JOIN ....... '); is simpler and clearer than actually trying to build it.. Regards Alan On Tue, 2005-07-26 at 11:23 -0700, Justin Patrin wrote: > On 7/26/05, David Alia <david.alia@gmail.com> wrote: > > > > > > -----Message d'origine----- > > De : Justin Patrin [mailto:papercrane@gmail.com] > > Envoyé : mardi 26 juillet 2005 19:32 > > À : David Alia > > Cc : pear-general@lists.php.net > > Objet : Re: [PEAR] Dataobject : complex jointures > > > > On 7/26/05, David Alia <david.alia@gmail.com> wrote: > > > > > > Hi. Thanks a lot for your -so quick- help. > > > > > > [cut] > > > > > > > > > > > $D->selectAdd(); > > > > $D->selectAdd('A1, A2, A3'); // fields from A table > > > > > > > > $B->joinAdd($E); > > > > > > > > $D->joinAdd($B); > > > > $D->selectAs(); > > > > > > >>Likely the above call is killing the A selectAdds from above. Try > > > >>removing > > > the above line and see what you get. > > > > > > --> this solved the problem : A fields are now available. > > > > > > > > > > > - SQL statement does not include A fields, nor E fields > > > > > > >> The A fields are missing likely due to the first selectAs call. The > > > >> E > > > fields aren't showing up because you didn't ask for them. Perhaps try > > > a selectAs call for A, B, *and* E. > > > > > > --> Ok, I thought I had already selected E fields using $B->joinAdd($E) ? > > > Since, E has no link with D, I canno't write $D->joinAdd($E)... > > > > > > > >>> Joining is not the same as setting up selected fields. joinAdd simply > > adds a join clause to your SQL. You empty out the SELECT part when you do > > selectAdd(), so no fields except the ones you specify will be shown. Try a > > selectAs for all 3 and see if that works. > > > > I must be an idiot but I can't get to do it : > > > > when I write : > > > > $D->selectAdd('A1, A2, A3, E1'); > > > > I get an error (unknown column E1) > > Does the E1 column exist? Is the join of E working? Try > DB_DataObject::debugLevel(1) to see the SQL that is generated and any > errors that may be happening. > > > > > when I write : > > > > $D->selectAs($E, 'E_%s'); > > > > I get an error (D has no link with E) > > > > I've tried lots of possibilities but nothing comes... > > > > Perhaps I was wrong about selectAs. I've never actually used it > myself. ;-) I tend to just use selectAdd. > > $D->selectAdd('A.A1, A.A2, A.A3, E.E1, E.E2, B.B1, etc...'); > >

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