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

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

问题描述

我有一个图像表,其中有一列名为 type.我只想更新所有行以将类型更改为 gallery,其中 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.

我正在使用此代码

    $this->Image->updateAll(array('Image.type' => 'gallery'), 
    array('Image.user_id' => $this->Auth->user('id')));

但我收到此错误:SQL 错误:1054:字段列表"中的未知列画廊"

为什么要将画廊添加到字段列表中?
语法不是应该将类型设置为画廊吗?

Why is gallery being added to the field list ?
Isn't the syntax supposed to set type to gallery?

谢谢!

推荐答案

手册:

$fields 数组接受 SQL 表达式.应手动引用文字值.

The $fields array accepts SQL expressions. Literal values should be quoted manually.

因此,以下应该有效:

$this->Image->updateAll(
    array('Image.type' => "'gallery'"), 
    array('Image.user_id' => $this->Auth->user('id'))
);

这篇关于CakePHP updateAll() 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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