Answer the question
In order to leave comments, you need to log in
How to correctly build a relationship between 3 tables?
Hello, there are 3 tables:
elements - Список элементов
permission - список разрешений для элементов
per_tariffs - список разрешений для тарифов пользователей
получаю permission по elements.type, затем получаю per_tariffs по permission.id
В моделе Elements:
public function getPermission(){
return $this->hasMany(Permissions::className(), ['type' => 'type'])
->viaTable('per_tariffs', ['per_id' => 'id']);
}
В контролере :
$model = Elements::find()
->with('permission')
->asArray()
->all();
.. debug($model);
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question