Doctrine2 findBy关系对象触发字符串转换错误 [英] Doctrine2 findBy relationship object triggers string conversion error
问题描述
<?php
// $ em instanceof EntityManager ,$ user instanceof Models\User
$ comments = $ em-> getRepository('Models\Comment')
- > findBy(array('user'=> $ user,' public'=> true));
...我收到一个PHP错误:
严重性:通知
消息:类的对象\用于字符串转换
文件名:DBAL / Connection.php
行号:574
$ b $这不应该发生,对吗?如果我使用QueryBuilder和setParameter('user',$ user),它的工作原理如下。
,但你必须通过标识符在那里。按对象查询尚未得到支持,只会使其成为2.1。
<?php
// $ em instanceof EntityManager,$ user instanceof Models\User
$ comments = $ em-> getRepository('Models\Comment')
- > findBy(array('user'=> $ user-> getId(),'public'=> true));
Say I have two entities in Doctrine2 that are related to each other, Models\User and Models\Comment. If I do this in Doctrine 2.0.0...
<?php
// $em instanceof EntityManager, $user instanceof Models\User
$comments = $em->getRepository('Models\Comment')
->findBy(array('user' => $user, 'public' => true));
...I get a PHP error:
Severity: Notice
Message: Object of class Models\User to string conversion
Filename: DBAL/Connection.php
Line Number: 574
This shouldn't happen, right? If I use the QueryBuilder and setParameter('user', $user) it works as expected.
Query by relationship is allowed, but you have to pass the Identifier in there. Query by object is not yet supported and will only make it into 2.1.
<?php
// $em instanceof EntityManager, $user instanceof Models\User
$comments = $em->getRepository('Models\Comment')
->findBy(array('user' => $user->getId(), 'public' => true));
这篇关于Doctrine2 findBy关系对象触发字符串转换错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!