ArrayHelper NOT EXISTS

Hi There,

I work for a school and have limited Yii knowledge. We use our application to manage loans of our assets.

This is a snippet from our ArrayHelper where our staff chooses the asset they wish to loan to a student.


<?= $form->field($model, 'lnAsset')->dropDownList(ArrayHelper::map(\common\models\Asset::find()->joinWith('assetschool', 'loan')->where(['aStatus'=>1,'e_assetSchool.school_id'=>$school])->all(), 'aId', 'objId'),['prompt'=>'Select']) ?>

The trouble we have is, this displays all assets including those that are already loaned out. I can get the information I need from our database with the following SQL;


SELECT aId, objId

FROM e_asset

WHERE e_asset.aStatus = 1 && NOT EXISTS (SELECT * FROM e_loan WHERE e_asset.aId = e_loan.lnAsset && lnStatus =1);

The trouble I am having is implementing the NOT EXISTS into the ArrayHelper, if anyone could assist that would be great.

Thank you

You don’t need to implement it into the ArrayHelper. You need to add a condition to the ActiveQuery that is returned by “find()”.

http://www.yiiframework.com/doc-2.0/yii-db-activequery.html