Re[3]: [PEAR] DB_DataObject 2 joins to same table

From: Date: Mon, 29 Nov 2004 09:19:10 +0000
Subject: Re[3]: [PEAR] DB_DataObject 2 joins to same table
References: 1 2 3  Groups: php.pear.general 
Request: Send a blank email to pear-general+get-15890@lists.php.net to get a copy of this message
Sorry!, I have seen in the documentation that the thing I want to do is very simple to do with a 4th parameter of joinAdd... string $joinCol - The column on This objects table to match,needed if this table links to the child object in multiple places eg. Example 26-1. using specific join Columns user->friend (is a id of a person) user->mother (is a id of another person) Just that I want. Thanks and sorry, people have to read!!!! Monday, November 29, 2004, 9:49:17 AM, vas escriure: LM> Hi Justin and thank you for your answer. LM> Yo are ok, use may be a column name, not a member of dataobject. LM> I have changed to factory instantation instead new Dataobect but my LM> problem is still present. LM> I will try to explain that I want to do again. Perhaps this time I'm LM> more clean. LM> If I have this tables LM> [USER] LM> user_id (pk) LM> user_name LM> user_firstcar LM> user_secondcar LM> [CAR] LM> car_id (pk) LM> car_name LM> car_color LM> car_model LM> and I want to retrieve all the users of the database but with the car LM> name instead of the car_id I have to use joins but... LM> How knows the user object what column links to each instance of car? LM> If I do: LM> $c1=DB_DataObject::factory('CAR'); LM> $c2=DB_DataObject::factory('CAR'); LM> $user=DB_DataObject::factory('USER'); $user->>joinAdd($c1); $user->>joinAdd($c2); LM> How knows the user instance that this last join is for LM> the user_secondcar column? How can I set it? LM> The SQL resultant query I want is: LM> SELECT * , CAR.car_name as c1_car_name , LM> CAR.car_name as c2_car_name LM> FROM USER LM> INNER JOIN CAR AS CAR ON CAR.car_id=USER.user_firstcar , LM> CAR AS c2 WHERE c2.car_id=USER.user_secondcar LM> And now I have: LM> SELECT * , CAR.car_name as c1_car_name , LM> CAR.car_name as c2_car_name LM> FROM USER LM> INNER JOIN CAR AS CAR ON CAR.car_id=USER.user_firstcar , LM> CAR AS c2 WHERE c2.car_id=USER.user_firstcar <--- I want user_secondcar here!!! LM> In the links.ini I have: LM> [USER] LM> USER_FIRSTCAR=CAR:CAR_ID LM> USER_SECOND=CAR:CAR_ID LM> The thing I want to do Is possible with dataobject and joins? LM> Thanks! LM> Friday, November 26, 2004, 10:51:19 PM, vas escriure: JP>> On Fri, 26 Nov 2004 14:16:50 +0100, Leo Márquez <leo@calidae.net> wrote: >>> Hi!, >>> >>> Hi have a tables relationship like the >>> 'Automatic Table Linking and Joins' example at PEAR DB_DAtaObject >>> Documentation. One table that have two columns that links to the same >>> table and the same column. For example: >>> >>> table USER >>> user_id >>> user_name >>> user_firstcar >>> user_secondcar >>> >>> table CAR >>> car_id >>> car_model >>> car_color >>> >>> on mydatabase.links.ini >>> >>> [USER] >>> user_firscar=CAR:car_id >>> user_secondcar=CAR:car_id >>> >>> In the PEAR doc example I see: >>> >>> ... >>> $car->use = 'first'; >>> ... >>> >>> I have been looking for the 'use' attribute in doc of DB_DAtaObject >>> and DB and not have seen it. I understand that in my code I should >>> type: JP>> Could you please give us a link to said documentation? I've never JP>> heard of a "use" member variable in DB_DataObject. In fact, I'm JP>> absolutely sure it doesn't exist as it would conflict with column JP>> names. >>> >>> $car->use='user_firstcar' for the first join >>> and >>> $car2->use='user_secondcar' for the first join >>> >>> and the selectAs, etc. >>> >>> I have tried it and not work, always see the first instance of car. My >>> code is here: >>> >>> $mo=new MAGATZEM(); JP>> You should really be using factory here. JP>> $mo = DB_DataObject::factory('MAGATZEM'); >>> $mo->use='MAGATZEM_ORIGEN'; >>> >>> $md=new MAGATZEM(); >>> $md->use='MAGATZEM_DESTI'; >>> >>> $dob->joinAdd($mo); >>> $dob->selectAs($mo,'mo_%s'); >>> >>> $dob->joinAdd($md,'','md'); >>> $dob->selectAs($md,'md_%s'); >>> >>> $dob->find(); >>> >>> Thanks about any help. >>> LM> -- LM> Salutacions, LM> Leo Márquez LM> [ Enginyeria del software / Internet ] LM> [ Calidae - www.calidae.com ] -- Salutacions, Leo Márquez [ Enginyeria del software / Internet ] [ Calidae - www.calidae.com ]

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