1
在CakePHP 2中我们可以在updateAll
方法中使用别名,但在CakePHP 3(测试3.4.9)中不能使用别名?CakePHP 3 updateAll带别名
$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 = ...
顺便说一句:上面的代码是从我的行为。
“_doesn't work_”不是一个合适的问题描述。即使问题对于了解CakePHP内部的人来说可能是显而易见的,请始终尽可能具体说明_exactly_发生了什么,以及您希望发生什么_exactly_。我想问题是生成的查询将在'UPDATE'子句中包含别名,而不是在'WHERE'子句中包含别名? – ndm
我添加了SQL代码... SQL看起来像'UPDATE cart_products SET ... WHERE CartProducts.id = ...'。 'cart_products'后面缺少'AS CartProducts' – kicaj
你从哪里看到生成的SQL?我期望'WHERE'子句没有别名(因为我可以在后面的答案中解释),而3.4.9的快速测试恰恰显示了对于我来说,'SET'子句中的别名,但没有WHERE条款。 – ndm