$model = Images::find() ->where(['product_id' => $id]) ->joinWith(['product' => function ($q) { $q->from('product'); }]) ->all(); if (Yii::$app->user->can('updateFabricatorImages', ['brand_id' => $model->product->brand_id])) { code } Trying to get property 'product' of non-object What is the reason?
var_dump ($ model) ;:
array(1) { [0]=> object(frontend\models\Images)#128 (11) { ["image"]=> NULL ["_attributes":"yii\db\BaseActiveRecord":private]=> array(5) { ["id"]=> int(5) ["url"]=> string(9) "115_0.jpg" ["product_id"]=> int(115) ["deleted"]=> NULL ["main"]=> NULL } ["_oldAttributes":"yii\db\BaseActiveRecord":private]=> array(5) { ["id"]=> int(5) ["url"]=> string(9) "115_0.jpg" ["product_id"]=> int(115) ["deleted"]=> NULL ["main"]=> NULL } ["_related":"yii\db\BaseActiveRecord":private]=> array(1) { ["product"]=> object(frontend\models\Products)#137 (10) { ["_attributes":"yii\db\BaseActiveRecord":private]=> array(5) { ["id"]=> int(115) ["name"]=> string(2) "wr" ["created_at"]=> int(1537185812) ["updated_at"]=> int(1537431514) ["brand_id"]=> int(4) } ["_oldAttributes":"yii\db\BaseActiveRecord":private]=> array(5) { ["id"]=> int(115) ["name"]=> string(2) "wr" ["created_at"]=> int(1537185812) ["updated_at"]=> int(1537431514) ["brand_id"]=> int(4) } ["_related":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_relationsDependencies":"yii\db\BaseActiveRecord":private]=> array(0) { } ["_errors":"yii\base\Model":private]=> NULL ["_validators":"yii\base\Model":private]=> NULL ["_scenario":"yii\base\Model":private]=> string(7) "default" ["_events":"yii\base\Component":private]=> array(2) { ["beforeInsert"]=> array(1) { [0]=> array(2) { [0]=> array(2) { [0]=> object(yii\behaviors\TimestampBehavior)#138 (7) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["skipUpdateOnClean"]=> bool(true) ["preserveNonEmptyValues"]=> bool(false) ["owner"]=> *RECURSION* } [1]=> string(18) "evaluateAttributes" } [1]=> NULL } } ["beforeUpdate"]=> array(1) { [0]=> array(2) { [0]=> array(2) { [0]=> object(yii\behaviors\TimestampBehavior)#138 (7) { ["createdAtAttribute"]=> string(10) "created_at" ["updatedAtAttribute"]=> string(10) "updated_at" ["value"]=> NULL ["attributes"]=> array(2) { ["beforeInsert"]=> array(2) { [0]=> string(10) "created_at" [1]=> string(10) "updated_at" } ["beforeUpdate"]=> string(10) "updated_at" } ["skipUpdateOnClean"]=> bool(true) ["preserveNonEmptyValues"]=> bool(false) ["owner"]=>