CakePHP updateAll()问题 [英] CakePHP updateAll() issues

查看:332
本文介绍了CakePHP updateAll()问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含类型列的图像表。我只想更新所有行,将类型更改为 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆