The code below is trying to limit the join table results to a particular product. It works if I hard-code a number into the condition. I want to pass $taskProductId into the dynamic function, but that is a PHP error (undefined variable). Is there another way to pass in that value?
$tasks = Task::find()
->joinWith(
[
'taskProducts' => function ($query, $taskProductId) {
$query->where('taskProduct.taskProductId=:taskProductId', [':taskProductId' =>taskProductId]);
},
'taskProducts.taskProductCriteria',
'taskProducts.taskProductStandards',
'taskProducts.taskProductCriteria.taskProductCriterionStatements',
])
->where('task.taskId=:taskId', [':taskId' => $taskId])
->asArray()
->all();
Thanks for any leads.