学说和zf2,在多侧得到一对多关系的最后结果


Doctrine and ZF 2, get the last result from a one-to-many relation in the many side

我有两个实体,一个叫news,另一个叫photoNews, news和photoNews是一对多的关系,它工作得很好。

当我上传图像时,我想要返回最后一个,并且使用jQuery我可以预览图像。这就是问题所在,我不能只检索最后一张图像。

一对多怎么可能只得到最近的多面呢?

我搜索了DQL,但没有很好的结果。我的代码如下:

$news = $this->getEm()->getRepository($obj)->find($idParent);
$photoNews = $parent->getPhotos();
var_dump($photoNews);

谢谢!

<?php
use Doctrine'Common'Collections'Criteria;
$group          = $entityManager->find('Group', $groupId);
$userCollection = $group->getUsers();
$criteria = Criteria::create()
    ->where(Criteria::expr()->eq("birthday", "1982-02-17"))
    ->orderBy(array("username" => Criteria::ASC))
    ->setFirstResult(0)
    ->setMaxResults(20)
;
$birthdayUsers = $userCollection->matching($criteria);

解决方案很简单,但问题是我使用var_dump来获取结果,使用var_dump它会导致许多信息并崩溃chrome。

谢谢。