Doctrine2 findBy relationship object triggers string conversion error(Doctrine2 findBy 关系对象触发字符串转换错误)
问题描述
假设我在 Doctrine2 中有两个相互关联的实体,ModelsUser 和 ModelsComment.如果我在 Doctrine 2.0.0 中这样做...
Say I have two entities in Doctrine2 that are related to each other, ModelsUser and ModelsComment. If I do this in Doctrine 2.0.0...
<?php
// $em instanceof EntityManager, $user instanceof ModelsUser
$comments = $em->getRepository('ModelsComment')
->findBy(array('user' => $user, 'public' => true));
...我收到一个 PHP 错误:
...I get a PHP error:
严重性:注意
消息:ModelsUser 类对象到字符串的转换
Message: Object of class ModelsUser to string conversion
文件名:DBAL/Connection.php
Filename: DBAL/Connection.php
行号:574
这不应该发生,对吧?如果我使用 QueryBuilder 和 setParameter('user', $user) 它会按预期工作.
This shouldn't happen, right? If I use the QueryBuilder and setParameter('user', $user) it works as expected.
推荐答案
允许按关系查询,但必须在那里传递标识符.尚不支持按对象查询,只会在 2.1 中实现.
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 ModelsUser
$comments = $em->getRepository('ModelsComment')
->findBy(array('user' => $user->getId(), 'public' => true));
这篇关于Doctrine2 findBy 关系对象触发字符串转换错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Doctrine2 findBy 关系对象触发字符串转换错误


- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP - if 语句中的倒序 2021-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01