我正在尝试在Symfony 2.3中创建一个查询,该查询应根据另一个表中的ID排除某些元素,例如我有一个SMS表和一个SMS_Deleted表,我需要从查询中排除来自SMS_Deleted的ID。
我有第一个查询来删除短信:
$sms_exceptions = $this->getDoctrine()
->getEntityManager()
->createQueryBuilder()
->select(array('s.idClient'))
->from('AloBundle:SmsDeleted', 's')
->getQuery()
->getResult();
在$sms_exceptions
中我应该从SMS查询中排除所有ID。然后在SMS Repository中我有这个:
public function findByClientArray($id_client, $sms_exceptions, $from, $to, $jtStartIndex, $jtPageSize)
{
$qb = $this->getEntityManager()->createQueryBuilder();
return $this->getEntityManager('voipswitch')
->createQueryBuilder()
->select(array('s.idClient, s.sentTime as date, s.toNumber as destiny, s.smsStatus as status, s.smsText as sms'))
->from('VoipswitchBundle:SmsOutbox', 's')
->where('s.idClient = :id_client AND s.sentTime >= :from AND s.sentTime <= :to')
->where($qb->expr()->notIn('s.idSms', $sms_exceptions))
->setParameter('id_client', $id_client)
->setParameter('from', new \DateTime($from))
->setParameter('to', new \DateTime($to))
->where($qb->expr()->notIn('s.idSms', $sms_exceptions))
->orderBy('s.sentTime', 'DESC')
->setFirstResult($jtStartIndex)
->setMaxResults($jtPageSize)
->getQuery()
->getArrayResult();
}
请帮忙???
由于
答案 0 :(得分:0)
我做这样的事情:
$queryBuilder = $this->getEntityManager()->createQueryBuilder();
$query = $queryBuilder
->select(['f'])
->from('AcmeDemoBundle:FirstEntity', 'f')
->leftJoin('AcmeDemoBundle:SecondEntity', 's', 'WITH', 'f.sId = s.id')
->where($queryBuilder->expr()->isNull('s.id'))
...
...
或与协会:
$queryBuilder = $this->getEntityManager()->createQueryBuilder();
$query = $queryBuilder
->select(['f'])
->from('AcmeDemoBundle:FirstEntity', 'f')
->leftJoin('f.secondEntity(ies)', 's')
->where($queryBuilder->expr()->isNull('s.id'))
...
...