I'm building a search form for secondhand cars. In the form the user can select checkboxes for the options the car should have. Because the user can select multiple options, i need to search a car that has all options the user has selected.
I'm trying to build a query that checks if the 'car' has the selected options. Right now im able to check if the car has one of the selected options by doing :
// The options filter is something special, the parameter is passed as a comma separated
// String with options ids
if($param == 'car.options' && $optionsIds){
$queryBuilder->leftJoin('car.options', 'option');
$options = $queryBuilder->expr()->orX();
foreach(explode(',', $optionsIds) as $id) {
$options->add($queryBuilder->expr()->eq('option.id', $id));
}
$wheres->add($options);
continue;
}
But when i change the 'orX' with an 'andX' the result is always returned empty.
The codesnippet above is part of a larger function.