【发布时间】:2018-02-15 14:43:10
【问题描述】:
我有两个模型,Bodyshops 和 BodyshopsSchedule
我以这样的多对多关系相互绑定
Entity/Bodyshops.php
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="App\Entity\BodyshopsSchedule", inversedBy="bodyshops")
* @ORM\JoinTable(name="join_bodyshops_bodyshopsSchedule")
*/
private $schedules;
实体/BodyshopsSchedule
/**
* @var \Doctrine\Common\Collections\Collection
*
* @ORM\ManyToMany(targetEntity="App\Entity\Bodyshops", mappedBy="schedules")
*/
private $bodyshops;
我在每个文件中为每个值创建了一个添加、获取和设置函数
我将它们绑定在一起,在 phpMyAdmin 中我可以在 joinTable 中看到一切都很好!
但是当我尝试打印 BodyshopsSchedule 跨 Bodyshops 类的属性时,它不起作用并且出现错误
类“Doctrine\ORM\PersistentCollection”的 ArrayAccess 对象中的键“0”不存在。
来自
<h5 id="{{bodyshop.id ~ '_city'}}" class="card-text"> {{ bodyshop.schedules[0].day }} </h5>
我尝试使用 {{ bodyshop.schedules.day|first }}
属性 "day" 和方法 "day()"、"getday()"/"isday()"/"hasday()" 或 "__call()" 都不存在并且具有公共在“Doctrine\ORM\PersistentCollection”类中访问。
在 for 中进行迭代
Key "" 用于键为 "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18、19、20、21" 不存在。
但我总是出错
我想知道如何获取 BodyshopsSchedule 而不是 PersistentCollection。
感谢阅读;)
【问题讨论】: