我有一个查询:
$q->andWhere($q->getRootAlias().'.is_published = ?', 1);
$q->andWhere($q->getRootAlias().'.published_at >= ?', time());
$q->leftJoin($q->getRootAlias().'.EventLdapGroup l');
$q->andWhereIn('l.ldap_group_id', $permissions_id );
$q->orWhere('l.ldap_group_id IS NULL);
输出:
FROM
Event r LEFT JOIN r.EventLdapGroup l
WHERE
r.is_published = ? AND
r.published_at >= ? AND
l.ldap_group_id IN (?, ?) OR
l.ldap_group_id IS NULL
唯一的问题是如果ldap_group_id
为空(最后一个条件),它将删除is_published
andpublished_at
条件。
我想要类似的东西[值在 ldap_group_id 中,或者它为空]:
FROM
Event r LEFT JOIN r.EventLdapGroup l
WHERE
r.is_published = ? AND
r.published_at >= ? AND
(l.ldap_group_id IN (?, ?) OR l.ldap_group_id IS NULL)
我必须说我迷失了复杂的 where 条件。如何做到这一点?
谢谢