我需要编写一个具有多个where条件和OR条件的查询。此OR条件仅在$location数组不为空时才会出现。所以只有当这个数组不为空时才需要参数。
我不确定如何在这种情况下编写此参数条件。
这是我正在处理的查询。
$qb = $this->createQueryBuilder("e")
->select(
"e.vehicleId",
"e.schemaId",
"e.location",
)
->andWhere("e.vehicleId = :vehicleId")
->andWhere("e.optionId = :optionId")
->andWhere("e.schemaId = :schemaId");
if (count($position) > 0) {
$qb->andWhere($qb->expr()->orX(
$qb->expr()->andX("e.location = :location"),
$qb->expr()->andX("e.location = :loc")
));
}
$qb->setParameters(array(
"vehicleId" => $vehicleId,
"schemaId" => $schemaId,
"location" => $position["location"],
"loc" => $position["loc"],
));
白衣非少年
慕神8447489