我有两个实体,一个叫新闻,另一个叫photoNews,新闻和photoNews是一对多的关系,它工作得很好。
当我上传一张图片时,我想要返回最后一张图片,并且使用jQuery我可以预览图片。这就是问题所在,我不能只检索最后一张图片。
怎么可能一对多只得到最近的一对多呢?
我搜索了DQL,但没有得到很好的结果。我的代码如下:
$news = $this->getEm()->getRepository($obj)->find($idParent);
$photoNews = $parent->getPhotos();
var_dump($photoNews);谢谢!
发布于 2014-07-23 06:23:44
<?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崩溃。
谢谢。
https://stackoverflow.com/questions/24898657
复制相似问题