PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » DB_DataObject » Bug #2216

joinAdd: JOIN ON custom conditions imposible

Details

Request #2216joinAdd: JOIN ON custom conditions imposible
Submitted2004-08-25 16:50 UTC
Fromfela at ds dot pg dot gda dot pl
Assignedalan_k
StatusClosed
PackageDB_DataObject
PHP Version5.0.0
OSLinux
Roadmaps(Not assigned)

Comments

[2004-08-25 16:50 UTC] fela at ds dot pg dot gda dot pl

Description:
------------
Hi.
Actually is imposible to create sql in joinAdd() with JOIN ... ON .. custom conditions. All conditions from joined objects are writen to WHERE section, but I think, better is write $obj->_cond to ON section.
because now INNER, LEFT and RIGHT JOIN work identical (as INNER)

if not, think if you could add new parametr to joinAdd() function, with custom conditions to ON section.

Thanks.

Reproduce code:
---------------
Example:

links[people][firm] = firm:id

* Actually:
$people->name = 'Smith';
$firm->joinAdd($people,'LEFT');
$firm->selectAdd();
$firm->selectAdd('firm.*, people.name');
$firm->type = 'big';
returned SQL:
SELECT firm.*, people.name
FROM firm
LEFT JOIN people AS people ON people.firm = firm.id
WHERE people.name = 'Smith' and firm.type = 'big';

expected SQL:
SELECT firm.*, people.name
FROM firm
LEFT JOIN people AS people ON
people.firm = firm.id AND people.name = 'Smith'
WHERE firm.type = 'big';

a difference in results is only in LEFT or RIGHT JOIN, not in INNER JOIN, now LEFT, RIGHT, and INNER return the same results and it is wrong.

[2005-02-18 08:20 UTC] sylfradev at yahoo dot fr

I've patched joinAdd method to use additional conditions :

1 - Replaced function signature :
function joinAdd($obj = false, $joinType='INNER', $joinAs=false, $joinCol=false, $additionalJoinsOn = NULL)

2 - Modified code in joinAdd
// $appendJoin = '';
$appendJoin = (isset($additionalJoinsOn)) ? 'AND ' . implode('AND ', $additionalJoinsOn) : '';

[2007-03-02 09:00 UTC] dsanders at baselinesolutions dot com dot au

Hi Alan, I've made a little patch against 1.429.

I've added a fifth optional parameter, where2On, that should turn on/off the requested behaviour.

I've moved the section where you cycle through the items of the joinee object up above the section where _join is modified. I also added the set property values to the joinee's where clause instead of the joiner's ($obj->whereAdd instead of $this->whereAdd) I've done this so that the condition is gathered together once when preg_replace is called on the joinee's _query['condition']. If where2On is set to true, then the condition is then prepended to the $appendJoin variable. Otherwise the condition is passed to whereAdd().

Here's the patch:

http://pyrus.sourceforge.net/DB_DataObject.php.patch