symfony - 返回 PersistentCollection 而不是 ArrayCollection

标签 symfony doctrine

不知道我做了什么.. 但现在,当我尝试获取相关属性时,我的实体返回“PersistentCollection”。

直到昨天它才返回“ArrayCollection”。
我无法在 PersistentCollection 中使用“foreach”,因此出现错误..

不知道我碰了什么来做这个......我必须检查什么?

最佳答案

我认为解决方案是使用持久集合和集合方法。 例如,您可以通过以下方式获取 Collection 的元素:

$array = $presistentCollectionObject->getValues();
foreach ($array as $obj) {
 dump($obj);
}

请注意,如果直接转储 PrecientCollection 对象,则元素 ArrayCollection(包含在其中)将为空。

关于symfony - 返回 PersistentCollection 而不是 ArrayCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36489012/

相关文章:

symfony - Internet Explorer 将 post 请求转换为 get 请求

angularjs - 为 .htaccess 重写规则(如果 index.html 不执行任何操作)

Symfony 3.4/路由 : Urlencoded "/" in the parameter value cause not matching the route

php - 如何使用 Doctrine 更改 mysql 表的 auto_increment

php - Symfony2 : Same codebase with multiple environments leads to tons of cache files

PHP Doctrine SoftDelete - 包括已删除的记录?

php - Symfony2 一页上的多个表单

jquery - 使用哪个 URL 从 React 组件调用 symfony 中的 API 函数,所有这些都在同一个应用程序中?

transactions - Doctrine 1.2 : Using postDelete to delete related files on filesystem -- with transaction support

php - Doctrine ODM 在运行时选择数据库