M
M
Maxim Grechushnikov2015-04-05 20:46:14
Yii
Maxim Grechushnikov, 2015-04-05 20:46:14

Yii2: has many on self. Why does looping happen?

There is a table of users. Each user can have a leader
id, leader_id and blah blah blah
I want to display all users whose leader I am

public function getTeam(){
     return $this->hasMany(self::className(), ['leader_id'=>'id']);
}

Cycling occurs. in the database the following
a99b323c26b54c068785ed2b7fb1a3d3.png
In short, I don’t see where my trouble is

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vyachin, 2015-04-07
@vyachin

It should be like this

public function getTeam(){
     return $this->hasMany(self::className(), ['id'=>'leader_id']);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question