multi model relation

user


id name

manager


id user_id

projects


id manager_id

From projects model how can I display name in user table.

yii establishes a relation between manager and projects

‘managers’ => array(self::BELONGS_TO, ‘manager’, ‘manager_id’),

so in the view I can display managers.user_id.

but I can I establish a relation between projects to managers and then to manager to user and get the name of the user

in projects table

For example for every manager_id in projects table I want look the user_id for that manager in manager table and then find the user name in User table?

Any help is appreciated. Thanks.

Look at the guide - relations using ‘through’.

However, I’d change your DB structure.

A manager is not a separate entity, just an attribute of a user. For example:

Users

id

manager_id #fk on self

Projects

id

manager_id

Projects_Users

id

projectId

userId

using relation, you may change database type from myisam into innodb.

as far as i know, changing into innodb you will get relation automatically created through gii