lykokane
(Filopoimin)
1
Hello to all,
Is there a way to pass a parameter to the anonymous function of joinWith for eager loading the relational data, besides the $query itself?
For example in the following I want to replace 100 with $var.
$var=1;
$customers = Customer::find()->joinWith([
'orders' => function ($query) {
$query->andWhere(['>', 'subtotal', 100]);
},
])->with('country')
->all();
Vojtech
(Vojtech Horak)
2
Try this:
http://php.net/manual/en/functions.anonymous.php
$var=1;
$customers = Customer::find()->joinWith([
'orders' => function ($query) use ($var) {
$query->andWhere(['>', 'subtotal', $var]);
},
])->with('country')
->all();
lykokane
(Filopoimin)
3
Thank you very much! And sorry to bother for just a php issue.