CakePHP updateAll()问题 [英] CakePHP updateAll() issues
问题描述
我有一个包含类型
列的图像表。我只想更新所有行,将类型更改为 gallery
,其中 user_id
匹配特定用户。 p>
我使用此代码
$ this-> Image-> ; updateAll(array('Image.type'=>'gallery'),
array('Image.user_id'=> $ this-> Auth-> user('id')));
但我得到这个错误: SQL Error:1054:Unknown column' 'in'field list'
为什么将图库添加到字段列表?
不是语法应该将类型设置为图库?
谢谢!
本文位于手册 :
$ fields数组接受SQL表达式。
因此,以下内容应该可以工作:
$ this-> Image-> updateAll(
array('Image.type'=>'gallery'),
array Image.user_id'=> $ this-> Auth-> user('id'))
);
I have an images table with a column called type
. I simply want to update all the rows to change the type to gallery
where the user_id
matches a particular user.
I am using this code
$this->Image->updateAll(array('Image.type' => 'gallery'),
array('Image.user_id' => $this->Auth->user('id')));
But I get this error: SQL Error: 1054: Unknown column 'gallery' in 'field list'
Why is gallery being added to the field list ?
Isn't the syntax supposed to set type to gallery?
Thanks!
Found this on the manual:
The $fields array accepts SQL expressions. Literal values should be quoted manually.
Thus, the following should work:
$this->Image->updateAll(
array('Image.type' => "'gallery'"),
array('Image.user_id' => $this->Auth->user('id'))
);
这篇关于CakePHP updateAll()问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!