I want to match related child entities field 'status' if it has one of the values ['not_started', 'in_progress']. I get an error "array to string conversion". Am I using it wrong?
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
/** @var ArrayCollection $tasks */
$criteria = Criteria::create()->where(Criteria::expr()->in('status', ['not_started', 'in_progress']));
/** @var Collection<int, Task> $openTasks */
$openTasks = $tasks->matching($criteria);
All other matching expressions are working because they use string instead of array but I need to check for multiple values at once and I don't want to use ArrayCollection->filter.
Edit:
I also tried this:
$statusValues = [Statuses::NOT_STARTED, Statuses::IN_PROGRESS];
/** @var ArrayCollection $tasks */
/** @var Expression[] $statusExpressions */
$statusExpressions = [];
foreach ($statusValues as $statusValue) {
$statusExpressions[] = Criteria::expr()->eq('status', $statusValue);
}
$criteria = Criteria::create()->orWhere(
Criteria::expr()->orX(
...$statusExpressions
),
);
/** @var Collection<int, Task> $openTasks */
$openTasks = $tasks->matching($criteria);
return $openTasks;
for some reason I get:
WHERE status = 'not_started' AND status = 'in_progress'
instead:
WHERE (status = 'not_started' OR status = 'in_progress')