Re: Structures_DataGrid, automatic DB_DataObject joinAdd experiment
| From: | Justin Patrin | Date: | Fri, 05 Jan 2007 23:11:29 +0000 |
| Subject: | Re: Structures_DataGrid, automatic DB_DataObject joinAdd experiment | ||
| References: | 1 2 3 4 5 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-26264@lists.php.net to get a copy of this message | ||
On 1/5/07, arnaud sellenet <demental@free.fr> wrote:
Le 2 janv. 07 à 05:07, Justin Patrin a écrit : If you're nesting links then you need to nest you joinAdd calls. $b->joinAdd($c); $a->joinAdd($b); $a->find() && $a->fetch(); Hi thanks for your reply after Olivier's message I send mine now.I guess my english failed ... I did not mean nested, I just ment something like 'self-linked'. Say we have a category table : ---------------------- id PK name varchar parent_id FK -> category.id ---------------------- This query : SELECT category.id , category.name , category.parent_id ,What does your links.ini look like? It sounds like you may have them backwards. -- Justin Patrintable0.idasparent_id__id,table0.nameasparent_id__name,table0.parent_idasparent_id__parent_idFROMcategoryLEFT JOINcategoryAStable0ONtable0.id=category.parent_idwhich is what I would like to obtain will return something like this : id name name 1 vehicle NULL 2 car vehicle 3 sports car car 4 bus vehicle 5 lorry vehicle 6 bmw sports car 7 ferrari sports car So the DB_DataObject creation and query should look like this (well that's what I hoped) : <?php $cat = & DB_DataObject::factory('category'); $parentcat = & DB_DataObject::factory('category'); $cat->joinAdd($parentcat,'LEFT','table0','parent_id'); $cat->selectAs($parentcat,'parent_id__%s','table0'); ?> But this code results in the DB_DataObject error : DataObjects_Category: ERROR: joinAdd: You cannot target a join column in the 'link from' table (category). Either remove the fourth argument to joinAdd() (parent_id), or alter your links.ini file. If I don't specify the joinCol (fourth argument for joinAdd), no error is raised but the query is wrong : SELECT category.id , category.name , category.parent_id ,table0.idasparent_id__id,table0.nameasparent_id__name,table0.parent_idasparent_id__parent_idFROMcategoryLEFT JOINcategoryAStable0ONtable0.parent_id=category.idResult : id name parent_id__name 1 vehicle car 1 vehicle bus 1 vehicle lorry 2 car sports car 3 sports car bmw 3 sports car ferrari 4 bus NULL 5 lorry NULL 6 bmw NULL 7 ferrari NULL Below is the code I've commented in DB/DataObject.php (lines 3087-3100). Commenting this code makes the four php lines above work as expected :// you have explictly specified the column // and the col is listed here.. // not sure if 1:1 table could cause probs here.. /* if ($joinCol !== false) { $this->raiseError( "joinAdd: You cannot target a join column in the" ."'link from' table ({$obj->__table}). " . "Either remove the fourth argument to joinAdd()"."({$joinCol}), or alter your links.ini file.", DB_DATAOBJECT_ERROR_NODATA); return false; } */Ok, so this portion of code seems to prevent from a potential bug. Could anyone show me an example ?