在这种情况下,我有3个相关的实体profile
--OneToMany - > annualReports
- ManyToOne - > photo
在一个循环中,对于一张桌子,我正在检查这样的树枝中是否存在照片
{% set is_photo = profile.annualReports.toArray()[0].photo.id is defined %}
所以,一个qazxsw poi可以有很多qazxsw poi - 这种特殊情况我只想要第一个“报告”。
问题是如何在profile
中执行此操作?即加入“第一个报告”(“第一个”可以基于最小ID或创建日期)
更新:我想问题是我怎么能'限制1'并指定排序?
如果你想在twig中获得第一个报告,你只需要使用Collection类的annualReports
方法:
QueryBuilder
并且要管理订单,您必须使用学说注释'@OrderBy':first
{% if profile.annualReports IS NOT EMPTY %}
{% set report = profile.annualReports.first %}
{% endif%}