mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Process query only when needed.
This commit is contained in:
parent
422be67a03
commit
0adc062cfa
2 changed files with 16 additions and 16 deletions
|
@ -318,10 +318,10 @@ class DataSource extends Object {
|
||||||
*
|
*
|
||||||
* @param string $query Query string needing replacements done.
|
* @param string $query Query string needing replacements done.
|
||||||
* @param array $data Array of data with values that will be inserted in placeholders.
|
* @param array $data Array of data with values that will be inserted in placeholders.
|
||||||
* @param string $association Name of association model being replaced
|
* @param string $association Name of association model being replaced.
|
||||||
* @param Model $Model Model instance
|
* @param Model $Model Model instance.
|
||||||
* @param array $stack
|
* @param array $stack
|
||||||
* @return string String of query data with placeholders replaced.
|
* @return mixed String of query data with placeholders replaced, or false on failure.
|
||||||
*/
|
*/
|
||||||
public function insertQueryData($query, $data, $association, Model $Model, $stack) {
|
public function insertQueryData($query, $data, $association, Model $Model, $stack) {
|
||||||
$keys = array('{$__cakeID__$}', '{$__cakeForeignKey__$}');
|
$keys = array('{$__cakeID__$}', '{$__cakeForeignKey__$}');
|
||||||
|
|
|
@ -1307,10 +1307,8 @@ class DboSource extends DataSource {
|
||||||
|
|
||||||
foreach ($resultSet as &$row) {
|
foreach ($resultSet as &$row) {
|
||||||
if ($type === 'hasOne' || $type === 'belongsTo' || $type === 'hasMany') {
|
if ($type === 'hasOne' || $type === 'belongsTo' || $type === 'hasMany') {
|
||||||
$query = $this->insertQueryData($queryTemplate, $row, $association, $Model, $stack);
|
|
||||||
|
|
||||||
$assocResultSet = array();
|
$assocResultSet = array();
|
||||||
if ($query !== false) {
|
|
||||||
if (
|
if (
|
||||||
($type === 'hasOne' || $type === 'belongsTo') &&
|
($type === 'hasOne' || $type === 'belongsTo') &&
|
||||||
isset($row[$LinkModel->alias], $joined[$Model->alias]) &&
|
isset($row[$LinkModel->alias], $joined[$Model->alias]) &&
|
||||||
|
@ -1321,6 +1319,8 @@ class DboSource extends DataSource {
|
||||||
$assocResultSet[0] = array($LinkModel->alias => $row[$LinkModel->alias]);
|
$assocResultSet[0] = array($LinkModel->alias => $row[$LinkModel->alias]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
$query = $this->insertQueryData($queryTemplate, $row, $association, $Model, $stack);
|
||||||
|
if ($query !== false) {
|
||||||
$assocResultSet = $this->fetchAll($query, $Model->cacheQueries);
|
$assocResultSet = $this->fetchAll($query, $Model->cacheQueries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue