Re: DB_DataObject->joinAdd
| From: | Ian Warner | Date: | Wed, 26 Jul 2006 09:21:29 +0000 |
| Subject: | Re: DB_DataObject->joinAdd | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-24771@lists.php.net to get a copy of this message | ||
Hi I haven't experimented much with the join functionality, I have a links file which makes it easier, why don't you want to create one of those?
Did you try the code I gave you?
You want to join presonrole to role
initially you had the factory call instancing the person class
so
$dataObject =& DB_DataObject::factory('personrole');
$foreignTable = 'role';
$foreignColumn = 'role_id';
$dataObject->joinAdd(array($key,$foreignTable.':'.$foreignColumn));
should give you the desired join
However the JoinAdd has 4 parameters
||void *$DB_DataObject->joinAdd*| ([object $dataobject [, string $joinType [, string $joinAs [, string $joinCol]]]])|
read here - http://pear.php.net/manual/en/package.database.db-dataobject.db-dataobject.joinadd.php
That seem to let you do what you want to acheive without the extra code:
*
/object $obj/ - joining object (no value resets the join)*
/string $joinType/ - "LEFT" | "INNER " | "RIGHT" | ""
INNER is default, "" indicates just select ... from a,b,c with no
join and links are added as where items.
Note: 'LEFT' is the same as LEFT OUTER.*
/string $joinAs/ - if you want to select the table as anther name
useful when you want to select multiple columns from a secondary
table.
*
/string $joinCol/ - The column on This objects table to
match,needed if this table links to the child object in multiple
places eg.
Regards
Ian Warner
Director
Triangle Solutions Ltd
http://www.triangle-solutions.com/
Skype:
TAG: iwarner_uk <callto:iwarner_uk>
TEL: +44 (207) 7871 2394 <callto:+4420778712394>
Japan:
TEL: +81 (3) 5261 5572 <callto:+81352615572>
FAX: +81 (3) 5261 5572 <callto:+81352615572>
MOB: +81 (90) 9312 1341 <callto:+819093121341>
UK:
TEL: +44 (1342) 311 923 <callto:+441342311923>
MOB: +44 (7980) 615 878 <callto:+447980615878>
©2000-2006 Triangle Solutions Ltd. - All rights reserved
Noel da Costa wrote:
*WOOOOOOSH!!!!* The sound of that going over my head ;-) Where would I specify that in the joinAdd syntax, Ian? Looking at the joinAdd method code, the table name for the second part of the 'ON' statement, (i.e. the 'person.' in "JOIN role ON role.role_id=**person.**role_id"), is always set to be the same table as the dataObject from which one calls the ->joinAdd.. so it seems to me that there is no way to do what I want to do with the existing code. I've come up with a non-intrusive patch for the joinAdd method that does allow what I'm trying to achieve. How would I go about submitting this for approval and possible addition to the PEAR DataObject class repository? Thanks, Noel On 26 Jul 2006, at 09:41, Ian Warner wrote:It seems then if you need it to match personrole then $dataObject =& DB_DataObject::factory('personrole'); $foreignTable = 'role'; $foreignColumn = 'role_id'; $dataObject->joinAdd(array($key,$foreignTable.':'.$foreignColumn)); you need to specify the two join table you have personrole and role Regards Ian Warner Director Triangle Solutions Ltd http://www.triangle-solutions.com/ Skype: TAG: iwarner_uk <callto:iwarner_uk> TEL: +44 (207) 7871 2394 <callto:+4420778712394> Japan: TEL: +81 (3) 5261 5572 <callto:+81352615572> FAX: +81 (3) 5261 5572 <callto:+81352615572> MOB: +81 (90) 9312 1341 <callto:+819093121341> UK: TEL: +44 (1342) 311 923 <callto:+441342311923> MOB: +44 (7980) 615 878 <callto:+447980615878> ©2000-2006 Triangle Solutions Ltd. - All rights reserved Noel da Costa wrote:--PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpThanks for the link. It looks like you are passing in a DataObject as the first argument of the joinAdd(), which is how the documentation on the PEAR site says it should be done - however, that requires a correctly configured links.ini file... I'm actually looking at a way of doing this that doesn't require a working links.ini file. My reason for this is that I have a custom DataObjects generator script that works in a different way to the link.ini file (more efficient for RAD in my case).. so I'm hoping that there is a way to set the table part of the foreign field name explicitly without having to pass a dataObject to joinAdd. Thanks, Noel On 26 Jul 2006, at 09:23, Ian Warner wrote:--PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ___________________________________________________________________ This message has been scanned by the Datanet MessageScreen Service. For more information please visit http://www.MessageScreen.co.ukHi at the bottom of this page is a join example that may help you. http://wiki.triangle-solutions.com/index.php/PEAR_DB_DataObject Regards Ian Warner Director Triangle Solutions Ltd http://www.triangle-solutions.com/ Noel da Costa wrote:--PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.phpHi there, I'm using this syntax for joinAdd: $dataObject =& DB_DataObject::factory('person'); $foreignTable = 'role'; $foreignColumn = 'role_id'; $dataObject->joinAdd(array($key,$foreignTable.':'.$foreignColumn)); which gives the following SQL: JOIN role ON role.role_id=person.role_id I'm trying (and failing) to change the "person." part before the last "role_id" I need this to match a different table (personrole), rather than the primary (person) table. How do I make this change within the systax for joinAdd? Thanks, Noel da Costa Lead Developer www.magharl.co.uk--PEAR General Mailing List (http://pear.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php ___________________________________________________________________ This message has been scanned by the Datanet MessageScreen Service. For more information please visit http://www.MessageScreen.co.uk