Bug #10241 [Opn]: Cascading joins when one involves composite keys fails
| From: | dsanders at baselinesolutions dot com dot au | Date: | Fri, 02 Mar 2007 07:11:31 +0000 |
| Subject: | Bug #10241 [Opn]: Cascading joins when one involves composite keys fails | ||
| References: | 1 | Groups: | php.pear.webmaster |
| Request: | Send a blank email to pear-webmaster+get-5741@lists.php.net to get a copy of this message | ||
Edit report at http://pear.php.net/bugs/bug.php?id=10241&edit=1
ID: 10241
User updated by: dsanders at baselinesolutions dot com dot au
Reported By: dsanders at baselinesolutions dot com dot au
Status: Open
Type: Bug
Package: Bug System
Operating System: Irrelevant
PHP Version: 5.2.1
New Comment:
Here's a patch (basically only use {$appendJoin} in the final
iteration):
@@ -3229,11 +3229,14 @@ class DB_DataObject extends DB_DataObjec
$key_count = count($ofield);
for($i = 0; $i < $key_count; $i++) {
if ($i == 0) {
- $this->_join .= " ON
{$joinAs}.{$ofield[$i]}={$table}.{$tfield[$i]} {$appendJoin} ";
+ $this->_join .= " ON
{$joinAs}.{$ofield[$i]}={$table}.{$tfield[$i]} ";
}
- else {
+ else if ($i == $key_count - 1) {
$this->_join .= " AND
{$joinAs}.{$ofield[$i]}={$table}.{$tfield[$i]} {$appendJoin} ";
}
+ else {
+ $this->_join .= " AND
{$joinAs}.{$ofield[$i]}={$table}.{$tfield[$i]} ";
+ }
}
} else {
$this->_join .= " ON
{$joinAs}.{$ofield}={$table}.{$tfield} {$appendJoin} ";
Previous Comments:
------------------------------------------------------------------------
[2007-03-02 02:02:54] dsanders at baselinesolutions dot com dot au
Description:
------------
When calling joinAdd() using composite keys and using a joinee object
that has already been joined to a third table, incorrect SQL is formed.
Test script:
---------------
links.ini:
[test_b]
fk_a,fk_b=test_a:key_a,key_b
fk_0 = test_0:id
$test_0 = DB_DataObject::factory('test_0');
$test_a = DB_DataObject::factory('test_a');
$test_b = DB_DataObject::factory('test_b');
$test_b->joinAdd($test_0);
$test_a->joinAdd($test_b);
DB_DataObject::debugLevel(1);
$test_a->find();
Expected result:
----------------
DO_Test_a: find:
DO_Test_a: QUERY: SELECT *
FROM test_a
INNER JOIN test_b ON test_b.fk_a=test_a.key_a AND
test_b.fk_b=test_a.key_b
INNER JOIN test_0 ON test_0.id=test_b.fk_0
Actual result:
--------------
DO_Test_a: find:
DO_Test_a: QUERY: SELECT *
FROM test_a
INNER JOIN test_b ON test_b.fk_a=test_a.key_a
INNER JOIN test_0 ON test_0.id=test_b.fk_0 AND
test_b.fk_b=test_a.key_b
INNER JOIN test_0 ON test_0.id=test_b.fk_0
------------------------------------------------------------------------
--
Edit this bug report at http://pear.php.net/bugs/bug.php?id=10241&edit=1