Answer the question
In order to leave comments, you need to log in
Yii2.Why can a table relationship cause a missing property error?
Good day.
Oddly enough, I have done this a million times already, but the day before yesterday something went wrong.
There are 2 tables: Lessons
- list of lessons and WatchedLesson
- viewed lessons. Contains 3 columns id, lesson_id, user_id.
And now I'm trying to link the lessons table with the viewed lessons table.
ModelLessons
public function getWatch(){
return $this->hasOne(WatchedLesson::class, ['lesson_id', 'id']);
}
$model = \app\models\Lessons::find()->where(['id' => 8])->with('watch')->one();
Getting unknown property: app\models\Lessons::lesson_id
lesson_id
this is a table field WachedLesson
, and not Lessons
lesson_id
I can get it like this: $model->watch->lesson_id
Answer the question
In order to leave comments, you need to log in
The issue has been resolved. Thanks to everyone and especially @usdglander
return $this->hasOne(WatchedLesson::class, ['lesson_id' => 'id']);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question