Skip to content

Commit b1c11ef

Browse files
committed
Fixes join with related models which have "associative" conditions.
Filtering for relations configured this way (associative conditions) was NOT working: ```php var $hasOne = array('Located' => array('conditions' => array( 'Located.model' => $Model->name, ))); ``` Filtering for relations configured this way was working: ```php var $hasOne = array('Located' => array('conditions' => array( "Located.model = {$Model->name}", ))); ```
1 parent 2558c80 commit b1c11ef

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

models/behaviors/filtered.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FilteredBehavior extends ModelBehavior
1818
/**
1919
* Keeps current values after filter form post.
2020
*
21-
* @var array
21+
* @var array
2222
*/
2323
var $_filterValues = array();
2424

@@ -171,7 +171,8 @@ function beforeFind(&$Model, $query)
171171
$customConditions = array($customConditions);
172172
}
173173

174-
$filterConditions = preg_replace(sprintf('#(?<![A-Za-z])%s(?![A-Za-z])#', $relatedModel->alias), $relatedModelAlias, $customConditions);
174+
175+
$filterConditions = $this->_replaceArrayKeysAndValues(sprintf('#(?<![A-Za-z])%s(?![A-Za-z])#', $relatedModel->alias), $relatedModelAlias, $customConditions);
175176
$conditions = array_merge($conditions, $filterConditions);
176177
}
177178

@@ -275,4 +276,15 @@ function _setFilterValues(&$Model, $method, $values = array())
275276

276277
$this->_filterValues[$Model->alias] = array_merge($this->_filterValues[$Model->alias], $values);
277278
}
279+
280+
function _replaceArrayKeysAndValues($pattern, $replacement, $input)
281+
{
282+
$keys = array_keys($input);
283+
$values = array_values($input);
284+
285+
$newKeys = preg_replace($pattern, $replacement, $keys);
286+
$newValues = preg_replace($pattern, $replacement, $values);
287+
288+
return array_combine($newKeys, $newValues);
289+
}
278290
}

0 commit comments

Comments
 (0)