Changed mergeAssociation scrubQueryData to be protected.

This commit is contained in:
Juan Basso 2011-08-21 21:18:11 -04:00
parent 689c7ffd45
commit e9390985ca
4 changed files with 26 additions and 20 deletions

View file

@ -1101,16 +1101,16 @@ class DboOracle extends DboSource {
if (empty($merge) && !isset($row[$association])) {
$row[$association] = $merge;
} else {
$this->__mergeAssociation($resultSet[$i], $merge, $association, $type);
$this->_mergeAssociation($resultSet[$i], $merge, $association, $type);
}
} else {
$this->__mergeAssociation($resultSet[$i], $fetch, $association, $type);
$this->_mergeAssociation($resultSet[$i], $fetch, $association, $type);
}
$resultSet[$i][$association] = $linkModel->afterfind($resultSet[$i][$association]);
} else {
$tempArray[0][$association] = false;
$this->__mergeAssociation($resultSet[$i], $tempArray, $association, $type);
$this->_mergeAssociation($resultSet[$i], $tempArray, $association, $type);
}
}
}

View file

@ -1016,7 +1016,7 @@ class DboSource extends DataSource {
* @return mixed boolean false on error/failure. An array of results on success.
*/
public function read(Model $model, $queryData = array(), $recursive = null) {
$queryData = $this->__scrubQueryData($queryData);
$queryData = $this->_scrubQueryData($queryData);
$null = null;
$array = array();
@ -1279,17 +1279,17 @@ class DboSource extends DataSource {
if (empty($merge) && !isset($row[$association])) {
$row[$association] = $merge;
} else {
$this->__mergeAssociation($row, $merge, $association, $type);
$this->_mergeAssociation($row, $merge, $association, $type);
}
} else {
$this->__mergeAssociation($row, $fetch, $association, $type, $selfJoin);
$this->_mergeAssociation($row, $fetch, $association, $type, $selfJoin);
}
if (isset($row[$association])) {
$row[$association] = $linkModel->afterFind($row[$association], false);
}
} else {
$tempArray[0][$association] = false;
$this->__mergeAssociation($row, $tempArray, $association, $type, $selfJoin);
$this->_mergeAssociation($row, $tempArray, $association, $type, $selfJoin);
}
}
}
@ -1362,7 +1362,7 @@ class DboSource extends DataSource {
* @param boolean $selfJoin
* @return void
*/
function __mergeAssociation(&$data, &$merge, $association, $type, $selfJoin = false) {
protected function _mergeAssociation(&$data, &$merge, $association, $type, $selfJoin = false) {
if (isset($merge[0]) && !isset($merge[0][$association])) {
$association = Inflector::pluralize($association);
}
@ -1446,8 +1446,8 @@ class DboSource extends DataSource {
* @return mixed
*/
public function generateAssociationQuery($model, $linkModel, $type, $association = null, $assocData = array(), &$queryData, $external = false, &$resultSet) {
$queryData = $this->__scrubQueryData($queryData);
$assocData = $this->__scrubQueryData($assocData);
$queryData = $this->_scrubQueryData($queryData);
$assocData = $this->_scrubQueryData($assocData);
$modelAlias = $model->alias;
if (empty($queryData['fields'])) {
@ -2123,7 +2123,7 @@ class DboSource extends DataSource {
* @param array $data
* @return array
*/
function __scrubQueryData($data) {
protected function _scrubQueryData($data) {
static $base = null;
if ($base === null) {
$base = array_fill_keys(array('conditions', 'fields', 'joins', 'order', 'limit', 'offset', 'group'), array());

View file

@ -1010,7 +1010,9 @@ class DboMysqlTest extends CakeTestCase {
$linkModel = $model->{$className};
$external = isset($assocData['external']);
$queryData = $this->Dbo->__scrubQueryData($queryData);
$reflection = new ReflectionMethod($this->Dbo, '_scrubQueryData');
$reflection->setAccessible(true);
$queryData = $reflection->invokeArgs($this->Dbo, array($queryData));
$result = array_merge(array('linkModel' => &$linkModel), compact('type', 'assoc', 'assocData', 'external'));
return $result;

View file

@ -92,6 +92,10 @@ class DboSourceTest extends CakeTestCase {
public function getLastQuery() {
return \$this->simulated[count(\$this->simulated) - 1];
}
public function mergeAssociation(&\$data, &\$merge, \$association, \$type, \$selfJoin = false) {
return parent::_mergeAssociation(\$data, \$merge, \$association, \$type, \$selfJoin);
}
}");
}
@ -177,7 +181,7 @@ class DboSourceTest extends CakeTestCase {
'updated' => '2007-03-17 01:18:31'
)
);
$this->testDb->__mergeAssociation($data, $merge, 'Topic', 'hasOne');
$this->testDb->mergeAssociation($data, $merge, 'Topic', 'hasOne');
$this->assertEqual($data, $expected);
$data = array('Article2' => array(
@ -200,7 +204,7 @@ class DboSourceTest extends CakeTestCase {
'id' => '1', 'user' => 'mariano', 'password' => '5f4dcc3b5aa765d61d8327deb882cf99', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31'
)
);
$this->testDb->__mergeAssociation($data, $merge, 'User2', 'belongsTo');
$this->testDb->mergeAssociation($data, $merge, 'User2', 'belongsTo');
$this->assertEqual($data, $expected);
$data = array(
@ -215,7 +219,7 @@ class DboSourceTest extends CakeTestCase {
),
'Comment' => array()
);
$this->testDb->__mergeAssociation($data, $merge, 'Comment', 'hasMany');
$this->testDb->mergeAssociation($data, $merge, 'Comment', 'hasMany');
$this->assertEqual($data, $expected);
$data = array(
@ -248,7 +252,7 @@ class DboSourceTest extends CakeTestCase {
)
)
);
$this->testDb->__mergeAssociation($data, $merge, 'Comment', 'hasMany');
$this->testDb->mergeAssociation($data, $merge, 'Comment', 'hasMany');
$this->assertEqual($data, $expected);
$data = array(
@ -293,7 +297,7 @@ class DboSourceTest extends CakeTestCase {
)
)
);
$this->testDb->__mergeAssociation($data, $merge, 'Comment', 'hasMany');
$this->testDb->mergeAssociation($data, $merge, 'Comment', 'hasMany');
$this->assertEqual($data, $expected);
$data = array(
@ -348,7 +352,7 @@ class DboSourceTest extends CakeTestCase {
)
)
);
$this->testDb->__mergeAssociation($data, $merge, 'Comment', 'hasMany');
$this->testDb->mergeAssociation($data, $merge, 'Comment', 'hasMany');
$this->assertEqual($data, $expected);
$data = array(
@ -389,7 +393,7 @@ class DboSourceTest extends CakeTestCase {
)
)
);
$this->testDb->__mergeAssociation($data, $merge, 'Tag', 'hasAndBelongsToMany');
$this->testDb->mergeAssociation($data, $merge, 'Tag', 'hasAndBelongsToMany');
$this->assertEqual($data, $expected);
$data = array(
@ -420,7 +424,7 @@ class DboSourceTest extends CakeTestCase {
),
'Tag' => array('id' => '1', 'tag' => 'Tag 1', 'created' => '2007-03-17 01:16:23', 'updated' => '2007-03-17 01:18:31')
);
$this->testDb->__mergeAssociation($data, $merge, 'Tag', 'hasOne');
$this->testDb->mergeAssociation($data, $merge, 'Tag', 'hasOne');
$this->assertEqual($data, $expected);
}