Answer the question
In order to leave comments, you need to log in
How to use data from two related tables?
good time of day question in the following there are two tables
serial=>id, name_serial, created_at;
films=>id, name_films, created_at,id_serial;
public function getFilms(){
return $this->hasMany(Films::className(),['id_serial'=>'id']);
}
public function getImages(){
return $this->hasMany(Image::className(), [ 'id_serial'=>'id' ]);
}
public function getSerial()
{
return $this->hasOne(Serial::className(), ['id'=>'id_serial']);
}
Answer the question
In order to leave comments, you need to log in
Use joinWith() or with() when making a request.
$films = Films::find()
->joinWith('serials')
->orderBy(['films.created_at' => SORT_DESC])
->addOrderBy(['serials.created_at' => SORT_DESC])
->all();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question