Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Removing magic variable in DboSource to bypass the adding of fields t…

…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...
commit ee2930d3d02f18ee04cd4e177cb0854c3ac25213 1 parent b22e30c
@lorenzo lorenzo authored
Showing with 6 additions and 11 deletions.
  1. +6 −11 lib/Cake/Model/Datasource/DboSource.php
View
17 lib/Cake/Model/Datasource/DboSource.php
@@ -196,14 +196,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
*
* @var array
@@ -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'];
@@ -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);
@@ -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;
}
@@ -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'])) {

0 comments on commit ee2930d

Please sign in to comment.
Something went wrong with that request. Please try again.