我有以下代码,当$ranges
是ArrayCollection时可以使用:
$startDateInRange = Criteria::expr()->andX(
Criteria::expr()->lte('startDate', $startDate),
Criteria::expr()->gte('endDate', $startDate)
);
$endDateInRange = Criteria::expr()->andX(
Criteria::expr()->lte('startDate', $endDate),
Criteria::expr()->gte('endDate', $endDate)
);
$isContainedByNewRange = Criteria::expr()->andX(
Criteria::expr()->gte('startDate', $startDate),
Criteria::expr()->lte('endDate', $endDate)
);
$criteria = Criteria::create()->where(
Criteria::expr()->orX(
$endDateInRange,
$startDateInRange,
$isContainedByNewRange
)
);
$overlappingRanges = $ranges->matching($criteria);
但是当$ranges
是PersistentCollection时,将生成错误的查询。 Criteria::expr()->orX
应该插入(a AND b) OR (c AND d)
,但应解释为AND字符串-a AND b AND c AND d
生成的真实where子句:
WHERE t.parentEntity_id = ?
AND te.startDate <= ?
AND te.endDate >= ?
AND te.startDate <= ?
AND te.endDate >= ?
AND te.startDate >= ?
AND te.endDate <= ?
我期望的是
WHERE t.parentEntity_id = ?
AND (
(te.startDate <= ? AND te.endDate >= ?)
OR (te.startDate <= ? AND te.endDate >= ?)
OR (te.startDate >= ? AND te.endDate <= ?)
)
我是否缺少某些东西,或者是教义中的错误?