我有一个相当复杂的查询如下:
return $this->createQueryBuilder('s')
->select('s')
->addSelect('COUNT(p.id) as HIDDEN c_id')
->leftJoin('s.owner', 'o')
->leftJoin('s.userPictures', 'p')
->leftJoin('o.transactions', 't')
->leftJoin('t.packType', 'pt')
->where('pt.id =:packId')
->setParameter('packId', $packId)
->andWhere('s.expirydate >=:expiryDate')
->setParameter('expiryDate', new \DateTime('now'))
->andWhere('c_id <:numberOfPictures')
->setParameter('numberOfPictures', $numberOfPictures)
->orderBy("c_id", 'DESC')
->groupBy('p.id')
->getQuery()
;
问题是查询是左对齐所有事务的。我希望它只与最近的交易保持联系。我怎样才能做到这一点?除了必须找到最近事务的事务ID并将其放入where子句之外,还有其他方法吗?
Transaction实体有一个已创建的列,实体如下所示:
class Transaction
{
/**
* @var datetime $created
* @Gedmo\Timestampable(on="create")
* @ORM\Column(type="datetime")
*/
protected $created;
}