Home » Database » DB_DataObject » Bug #5307
Method to remove duplicate join declarations
Details
| Request #5307 | Method to remove duplicate join declarations |
|---|---|
| Submitted | 2005-09-06 09:19 UTC |
| From | torsten dot roehr at gmx dot de |
| Status | Suspended |
| Package | DB_DataObject |
| PHP Version | Irrelevant |
| OS | Irrelevant |
| Roadmaps | (Not assigned) |
Comments
[2005-09-06 09:19 UTC] torsten dot roehr at gmx dot de
Description:
------------
When building an object with multiple join objects for a complex search form it may occur that joins may be added multiple times depending on the entered search form values.
As this is very hard to control in the application (a lot of nested if/else may be required) I would like to see the following method added:
Test script:
---------------
function removeDuplicateJoins()
{
if (!empty($this->_join)) {
$joins = explode("\n", $this->_join);
$joins = array_map('trim', $joins);
$joins = array_unique($joins);
$this->_join = implode("\n", $joins);
}
}
This will remove duplicate join declarations and needs to be called once in the find() method before building the query:
$this->removeDuplicateJoins();
$sql = 'SELECT ' .
$this->_query['data_select'] .
' FROM ' . ($quoteIdentifiers ? $DB->quoteIdentifier($this->__table) : $this->__table) . " " .
$this->_join .
$this->_query['condition'] . ' '.
$this->_query['group_by'] . ' '.
$this->_query['having'] . ' '.
$this->_query['order_by'] . ' ';
Thanks for having a look and best regards,
Torsten Roehr