Relation queries on-the-fly

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();



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();

Thank you very much! And sorry to bother for just a php issue.