A
A
andr20172016-08-25 12:47:01
Yii
andr2017, 2016-08-25 12:47:01

How to properly declare relationships in Active Record in Yii?

There is a UserModel class that implements Active Record.
There is a UserGroupsSummary class that implements Active Record.
Unable to make connections. Error Invalid argument supplied for foreach()
Each user can have an arbitrary number of values ​​in the UserGroupsSummary. UserGroupsSummary (contains the id_users field which refers to the Users table id field).
Am I linking correctly?
UsersModel:
public function relations() {
return [
'user_groups_summary' => [self::HAS_MANY, 'UserGroupsSummary', ['id_users' => 'id']],
];
}
Model UserGroupsSummary:
public function relations()
{
return [
'user' => [self::BELONGS_TO, 'UsersModel', ['id_users' => 'id1']],
];
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2016-08-25
@andr2017

Good afternoon.

// поменяйте местами id
// что за id1?
// BELONGS_TO точно не помню, но HAS_ONE возможно
'user' => [self::BELONGS_TO, 'UsersModel', ['id_users' => 'id1']],

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question