在 CakePHP 2 中我们可以在updateAll
方法中使用别名,但在 CakePHP 3(测试 3.4.9)中不能使用别名?
$this->_table->updateAll([
$this->_table->getAlias() . '.deleted' => Time::now()
], [
$this->_table->getAlias() . '.' . $this->_table->getPrimaryKey() => $entity->{$this->_table->getPrimaryKey()}
]);
如果您的表是products
并且别名是它是有效的,但如果您的表是并且别名是Products
则不起作用cart_products
CartProducts
SQL 应如下所示:
UPDATE cart_products AS CartProducts SET... WHERE CartProducts.id = ...
而不是
UPDATE cart_products SET... WHERE CartProducts.id = ...
顺便说一句:上面的代码来自我的行为。