DboSource::_matchRecords PHP Method

_matchRecords() protected method

Gets a list of record IDs for the given conditions. Used for multi-record updates and deletes in databases that do not support aliases in UPDATE/DELETE queries.
protected _matchRecords ( Model $Model, mixed $conditions = null ) : array
$Model Model The model to find matching records for.
$conditions mixed The conditions to match against.
return array List of record IDs
    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;
    }
DboSource