Re: Dataobject : complex jointures

From: Date: Tue, 26 Jul 2005 17:17:24 +0000
Subject: Re: Dataobject : complex jointures
References: 1 2  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-20145@lists.php.net to get a copy of this message
On 7/26/05, David Alia <david.alia@gmail.com> wrote: > Hello all, > > Thanks for the answers you already gave me. > > Now I'm trying more complicated, if someone is kind enough to read it... :) > > Suppose I have this structure : > > A, B, C are "primary tables". The link between all these tables is the > central table D. > B is linked to another table E by a foreign key. > > > A <- D -> B -> E > ^ > | > C > > The point is : I want to get in a single query all records from D, "inner > joining" A, B and C and using the relationship between B and E. > > The code I wrote is the following : > > $a = array(); > > DB_DataObject::debugLevel(2); > > $D = $this->factory('D'); > $A = $this->factory('A'); > $E = $this->factory('E'); > $B = $this->factory('B'); > > $D->joinAdd($this); // $this is $C, already initialized > $D->joinAdd($A); > > $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. > $D->selectAs($B, 'B_%s'); > > > if ($D->find()) { > while ($D->fetch()) { > $a[] = $D; > } > } > return $a; > > I get this result : > > - 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. > - B fields are correctly labeled (ie B_field) > - A1, A2 and A3 are not included too > > Can anyone help me to find out the problem ? > > Thanks a lot > > David > > -- > PEAR General Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Justin Patrin

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