protected function _matchRecords(Model $Model, $conditions = null)
{
if ($conditions === true) {
$conditions = $this->conditions(true);
} elseif ($conditions === null) {
$conditions = $this->conditions($this->defaultConditions($Model, $conditions, false), true, true, $Model);
} else {
$noJoin = true;
foreach ($conditions as $field => $value) {
$originalField = $field;
if (strpos($field, '.') !== false) {
list(, $field) = explode('.', $field);
$field = ltrim($field, $this->startQuote);
$field = rtrim($field, $this->endQuote);
}
if (!$Model->hasField($field)) {
$noJoin = false;
break;
}
if ($field !== $originalField) {
$conditions[$field] = $value;
unset($conditions[$originalField]);
}
}
if ($noJoin === true) {
return $this->conditions($conditions);
}
$idList = $Model->find('all', array('fields' => "{$Model->alias}.{$Model->primaryKey}", 'conditions' => $conditions));
if (empty($idList)) {
return false;
}
$conditions = $this->conditions(array($Model->primaryKey => Hash::extract($idList, "{n}.{$Model->alias}.{$Model->primaryKey}")));
}
return $conditions;
}