Activerecord Eager Loading

From official guide Docs




class Customer extends \yii\db\ActiveRecord

{

    public function getBigOrders($threshold = 100)

    {

        return $this->hasMany(Order::className(), ['customer_id' => 'id'])

            ->where('subtotal > :threshold', [':threshold' => $threshold])

            ->orderBy('id');

    }

}



How can I achieve the following:




$customers = Customer::find()

  ->with('bigOrders') //here I need to provide $threshold somehow

  ->all();

Maybe…


$customers = Customer::find()

  ->with(['bigOrders'=>function($query){

   $query->andWhere('threshold > :threshold',[

   ':threshold'=>$threshold

]);

}])

  ->all();

I understand how to achieve the result, but I need it without code duplicate (Imagine if there is complicated query and I need it in few places).