From ee2930d3d02f18ee04cd4e177cb0854c3ac25213 Mon Sep 17 00:00:00 2001 From: Jose Lorenzo Rodriguez Date: Tue, 28 Jun 2011 11:45:37 -0430 Subject: [PATCH] Removing magic variable in DboSource to bypass the adding of fields to association queries, instead adding the ability to declare 'fields' => false in the association array. This opens the possibility of having joins for filtering purposes. --- lib/Cake/Model/Datasource/DboSource.php | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/Cake/Model/Datasource/DboSource.php b/lib/Cake/Model/Datasource/DboSource.php index 7ba047ed2..933c5f2a0 100644 --- a/lib/Cake/Model/Datasource/DboSource.php +++ b/lib/Cake/Model/Datasource/DboSource.php @@ -195,14 +195,6 @@ class DboSource extends DataSource { */ public $endQuote = null; -/** - * Bypass automatic adding of joined fields/associations. - * - * @var boolean - * @access private - */ - private $__bypass = false; - /** * The set of valid SQL operations usable in a WHERE statement * @@ -1036,7 +1028,7 @@ class DboSource extends DataSource { $null = null; $array = array(); $linkedModels = array(); - $this->__bypass = false; + $bypass = false; if ($recursive === null && isset($queryData['recursive'])) { $recursive = $queryData['recursive']; @@ -1048,7 +1040,7 @@ class DboSource extends DataSource { } if (!empty($queryData['fields'])) { - $this->__bypass = true; + $bypass = true; $queryData['fields'] = $this->fields($model, null, $queryData['fields']); } else { $queryData['fields'] = $this->fields($model); @@ -1069,6 +1061,9 @@ class DboSource extends DataSource { $linkModel->getDataSource(); if ($model->useDbConfig === $linkModel->useDbConfig) { + if ($bypass) { + $assocData['fields'] = false; + } if (true === $this->generateAssociationQuery($model, $linkModel, $type, $assoc, $assocData, $queryData, $external, $null)) { $linkedModels[$type . '/' . $assoc] = true; } @@ -1501,7 +1496,7 @@ class DboSource extends DataSource { $self = $model->name === $linkModel->name; $fields = array(); - if ($external || (in_array($type, array('hasOne', 'belongsTo')) && $this->__bypass === false)) { + if ($external || (in_array($type, array('hasOne', 'belongsTo')) && $assocData['fields'] !== false)) { $fields = $this->fields($linkModel, $association, $assocData['fields']); } if (empty($assocData['offset']) && !empty($assocData['page'])) {