I
I
Igor Bezlepkin2019-08-28 15:41:09
Yii
Igor Bezlepkin, 2019-08-28 15:41:09

Why doesn't Yii2 return all fields on JeftJoin?

Hey! I'm trying to get the required fields:

return $this->hasMany(FileUsage::className(), ['usage_id' => 'id'])
            ->select('f.id, f.user_id, f.type_id, f.name, f.mime, f.size, fu.usage_id')
            ->alias('fu')
            ->leftJoin('file f', 'f.id = fu.file_id')
            ->where(['in', 'f.type_id', $fileTypes])
            ->andWhere(['fu.is_deleted' => FileUsage::IS_NOT_DELETED])
            ->orderBy(['fu.id' => SORT_DESC])
            ->limit(1);
    }

But it takes only the first two (f.id, f.user_id) and the last one from the main table fu.usage_id

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question