Skip to content

Commit

Permalink
Removing magic variable in DboSource to bypass the adding of fields t…
Browse files Browse the repository at this point in the history
…o association queries, instead adding the ability to declare 'fields' => false in the association array. This opens the possibility of having joins for filtering purposes.
  • Loading branch information
lorenzo committed Jun 28, 2011
1 parent b22e30c commit ee2930d
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions lib/Cake/Model/Datasource/DboSource.php
Expand Up @@ -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
*
Expand Down Expand Up @@ -1036,7 +1028,7 @@ public function read($model, $queryData = array(), $recursive = null) {
$null = null;
$array = array();
$linkedModels = array();
$this->__bypass = false;
$bypass = false;

if ($recursive === null && isset($queryData['recursive'])) {
$recursive = $queryData['recursive'];
Expand All @@ -1048,7 +1040,7 @@ public function read($model, $queryData = array(), $recursive = null) {
}

if (!empty($queryData['fields'])) {
$this->__bypass = true;
$bypass = true;
$queryData['fields'] = $this->fields($model, null, $queryData['fields']);
} else {
$queryData['fields'] = $this->fields($model);
Expand All @@ -1069,6 +1061,9 @@ public function read($model, $queryData = array(), $recursive = null) {

$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;
}
Expand Down Expand Up @@ -1501,7 +1496,7 @@ public function generateAssociationQuery($model, $linkModel, $type, $association
$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'])) {
Expand Down

0 comments on commit ee2930d

Please sign in to comment.