S
S
Sergey Beloventsev2018-05-22 09:53:17
Yii
Sergey Beloventsev, 2018-05-22 09:53:17

How to get all links of a model?

Actually there are several related models

public function getState0() {
    return $this->hasOne(Reference::class, ['id' => 'state']);
  }

public function getMain_document() {
    return $this->hasOne(MainDocuments::class, ['employee_id' => 'id']);
  }

how can i get them all. Something like
$models=User::findOne(1);
$models->getRealtions();//только это я так понимаю другой метод

The thing is, I don't really know how many connections there will be. But you have to get them all.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Bay, 2018-05-22
@kawabanga

->with(['state0','main_document'])->all();

M
Maxim Timofeev, 2018-05-22
@webinar

public function getRelByClass($class,$params) {
    return $this->hasOne($class, $params);
}

But why not pull then himself hasOne?
I think the problem is in the structure. Describe the task. Why an unlimited number of related tables?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question