0

当我使用\Doctrine\Common\Collections\Criteria::create()

use Doctrine\Common\Collections\Criteria;
...
$criteria = Criteria::create();
$criteria->where(Criteria::expr()->eq('isPublished', 1))
        ->andWhere(Criteria::expr()->eq('isDeleted', 0));

$this->comments->matching($criteria)

我得到错误:

Message:
An exception occurred while executing 'SELECT t0.id AS id1, t0.rating AS rating2, t0.text AS text3, t0.username AS username4, t0.isPublished AS isPublished5, t0.isDeleted AS isDeleted6, t0.dateCreated AS dateCreated7, t0.userIP AS userIP8, t0.user_id AS user_id9, t0.product_id AS product_id10 FROM product_comments t0 WHERE ((t0.isPublished IS ? AND t0.isDeleted IS ?) AND t0.product_id IS ?)' with params {"1":1,"2":0,"3":1123}:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1 AND t0.isDeleted IS 0) AND t0.product_id*IS 1123)' at line 1

问题是 where 子句中的操作数“IS”。它不是 MySQL 操作数。(如果我将此查询粘贴到 MySQL 终端,并更改 "IS" => "=" - 就可以了) 为什么 Doctrine 生成这样的查询?问题出在哪里?

4

3 回答 3

1

这是通过将 Doctrine ORM 升级到 2.3.5 或更高版本修复的教义错误。错误报告http://www.doctrine-project.org/jira/browse/DDC-2471 _

于 2014-06-20T19:22:40.783 回答
1

我解决了更改 Doctrine\ORM\Persisters\BasicEntityPersister 的第 91 行

Comparison::IS  => 'IS %s',

Comparison::IS  => '= %s',
于 2014-02-07T18:44:32.970 回答
-1

尝试更换

  expr()->eq('isPublished', 1)  and expr()->eq('isPublished', 0) with

 expr()->eq('isPublished', '?1')
 expr()->eq('isPublished', '?0')
于 2013-08-08T05:38:45.363 回答