Hi Folks,
I need to pass a second argument to the anonimous function used by the joinWith() method. I am trying to do this way:
$model = new Product();
$model->section_id = 1;
$model->load(Yii::$app->request->post());
$listOptions = ArrayHelper::map(VariationOption::find()->joinWith([
'variation.sections' => function ($query, $model) { // need second argument here
$query->andWhere(['section.id' => $model->section_id]); // need to use it here
},
])->all(), 'id', 'option', 'variation.name');
That results:
PHP Warning – yii\base\ErrorException
Missing argument 2 for backend\controllers\ProductController::backend\controllers\{closure}()
Using just the $query argument and a hardcoded id inside the function works although.
Am I doing something wrong? Is there a way to achieve that?
Thanks in advance.
EDIT: ** Sorry about the typo in the title. **