updateAll从字段中删除引号

时间:2015-04-17 01:55:33

标签: php mysql cakephp

我的控制器中有这个功能......

public function updateMany() {
    $fields = $this->request->data['fields'];
    $conditions = $this->request->data['conditions'];
    if(!$this->request->is('post')) {
        throw new BadRequestException('Method must be POST.', 400);
    } else {
        if ($this->{$this->modelClass}->updateAll($fields, $conditions)) {
            $message = 'Saved, '. $this->{$this->modelClass}->getAffectedRows() .' rows affected.';
        } else {
            throw new BadRequestException('An error occurred while saving.', 500);
        }
    }
    $this->response->statusCode(200);
    $this->set(array(
            'message' => $message,
            '_serialize' => array('message')
    ));
}

我正在传递以下JSON:

{
  "fields": {"foo": "bar"},
  "conditions": {"foo": "baz"}
}

我的回答是:

{
    "code": 500,
    "name": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'bar' in 'field list'",
    "message": "SQLSTATE[42S22]: Column not found: 1054 Unknown column 'bar' in 'field list'",
    "url": "\/site\/foobars\/updateMany",
    "error": {
        "errorInfo": [
            "42S22",
            1054,
            "Unknown column 'bar' in 'field list'"
        ],
        "queryString": "UPDATE `website`.`foobars` AS `FooBar`  SET `FooBar`.`foo` = bar  WHERE `disguise` = 'baz'"
    }
}

问题是:

SET `FooBar`.`foo` = bar

应该是:

SET `FooBar`.`foo` = 'bar'

WHERE工作正常...为什么引号会从updateAll()函数中的SET中删除?

foo结构:varchar(50) utf8_general_ci

0 个答案:

没有答案