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 关系对象触发字符串转换错误


基础教程推荐
- 如何替换eregi() 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01