Answer the question
In order to leave comments, you need to log in
How do you display items by id through a linked table in Yii2?
I have an intermediate table.
Let's say we have a relationship between three tables.
tovar zakaz_tovar user
id id id
title id_tovar name
id_user
public function getUser(){
return $this->hasMany(User:className(), ['id' => 'id_user'])
->viaTable('zakaz_tovar', ['id_tovar' => 'id']);
}
Answer the question
In order to leave comments, you need to log in
Add to condition.->orderBy('id ASC');
public function getUser(){
return $this->hasMany(User:className(), ['id' => 'id_user'])
->viaTable('zakaz_tovar', ['id_tovar' => 'id'])->orderBy('id_tovar ASC');
}
public function getUser(){
return $this->hasMany(User:className(), ['id' => 'id_user'])
->viaTable('zakaz_tovar', ['id_tovar' => 'id'])->orderBy('id DESC');
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question