mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 11:28:25 +00:00
Merging fixes and enhancements into trunk
Revision: [1925] Adding fix for association conditions when set in the association array Revision: [1924] Adding fixes for $recursive Revision: [1923] Adding fix from Ticket #362 git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1926 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
934cfe1dac
commit
c2dcc10996
3 changed files with 36 additions and 6 deletions
|
@ -6,4 +6,4 @@
|
|||
// +---------------------------------------------------------------------------------------------------+ //
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
0.10.8.1922 RC 4
|
||||
0.10.8.1926 RC 4
|
|
@ -370,6 +370,7 @@ class DboSource extends DataSource
|
|||
$this->__assocJoins = null;
|
||||
if(!is_null($recursive))
|
||||
{
|
||||
$_recursive = $model->recursive;
|
||||
$model->recursive = $recursive;
|
||||
}
|
||||
|
||||
|
@ -435,7 +436,7 @@ class DboSource extends DataSource
|
|||
foreach ($resultSet[$i][$linkModel->name] as $value)
|
||||
{
|
||||
$datas[][$linkModel->name] = $value[$linkModel->primaryKey];
|
||||
$fetch = $this->queryDeepAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $array, false, $datas);
|
||||
$fetch = $this->queryDeepAssociation($linkModel, $deepModel, $type1, $assoc1, $assocData1, $array, true, $datas);
|
||||
unset($datas);
|
||||
|
||||
if (!empty($fetch[0]))
|
||||
|
@ -474,6 +475,11 @@ class DboSource extends DataSource
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!is_null($recursive))
|
||||
{
|
||||
$model->recursive = $_recursive;
|
||||
}
|
||||
return $resultSet;
|
||||
}
|
||||
|
||||
|
@ -506,8 +512,6 @@ class DboSource extends DataSource
|
|||
*/
|
||||
function queryAssociation(&$model, &$linkModel, $type, $association, $assocData, &$queryData, $external = false, &$resultSet)
|
||||
{
|
||||
//$external = (($linkModel->db === $this) && $resultSet == null);
|
||||
|
||||
$query = $this->generateAssociationQuery($model, $linkModel, $type, $association, $assocData, $queryData, $external, $resultSet);
|
||||
if ($query)
|
||||
{
|
||||
|
@ -695,6 +699,19 @@ class DboSource extends DataSource
|
|||
$sql .= ' AS '.$this->name($alias).' ON '.$this->name($alias).'.';
|
||||
$sql .= $this->name($assocData['foreignKey']).'='.$model->escapeField($model->primaryKey);
|
||||
$sql .= $this->order($assocData['order']);
|
||||
|
||||
if (isset($assocData['conditions']))
|
||||
{
|
||||
if(is_array($queryData['conditions']))
|
||||
{
|
||||
$queryData['conditions'] = array_merge($assocData['conditions'], $queryData['conditions']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$queryData['conditions'] = $assocData['conditions'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!in_array($sql, $queryData['joins']))
|
||||
{
|
||||
$queryData['joins'][] = $sql;
|
||||
|
@ -745,6 +762,19 @@ class DboSource extends DataSource
|
|||
$sql .= ' AS ' . $this->name($alias) . ' ON ';
|
||||
$sql .= $this->name($model->name).'.'.$this->name($assocData['foreignKey']);
|
||||
$sql .= '='.$this->name($alias).'.'.$this->name($linkModel->primaryKey);
|
||||
|
||||
if (isset($assocData['conditions']))
|
||||
{
|
||||
if(is_array($queryData['conditions']))
|
||||
{
|
||||
$queryData['conditions'] = array_merge($assocData['conditions'], $queryData['conditions']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$queryData['conditions'] = $assocData['conditions'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!in_array($sql, $queryData['joins']))
|
||||
{
|
||||
$queryData['joins'][] = $sql;
|
||||
|
|
|
@ -156,13 +156,13 @@ class DboMysql extends DboSource
|
|||
elseif (count($args) > 1 && strpos($args[0], 'findBy') === 0)
|
||||
{
|
||||
$field = Inflector::underscore(str_replace('findBy', '', $args[0]));
|
||||
$query = '`' . $args[2]->name . '.' . $field . '` = ' . $this->value($args[1][0]);
|
||||
$query = '`' . $args[2]->name . '`.`' . $field . '` = ' . $this->value($args[1][0]);
|
||||
return $args[2]->find($query);
|
||||
}
|
||||
elseif (count($args) > 1 && strpos($args[0], 'findAllBy') === 0)
|
||||
{
|
||||
$field = Inflector::underscore(str_replace('findAllBy', '', $args[0]));
|
||||
$query = '`' . $args[2]->name . '.' . $field . '` = ' . $this->value($args[1][0]);
|
||||
$query = '`' . $args[2]->name . '`.`' . $field . '` = ' . $this->value($args[1][0]);
|
||||
return $args[2]->findAll($query);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue