Hi,
I am very new to Yii. I have this kind of relation:
User(id, name, …)
Project(id, name, …)
Role(id, name, …)
UserRoleProject(userid, roleid, projectid)
Underline items are primary keys. All are MANY_MANY.
The question is: "How can I define the relation in each of model User, Project, Role.
In model User, I have tried to declare:
'roles'=>array(self::MANY_MANY, 'role'=>'userprojectrole(userid,projectid,roleid)', 'alias'=>'roles', 'together'=>true),
'projects'=>array(self::MANY_MANY, 'project'=>'userprojectrole(userid,roleid,projectid)', 'alias'=>'projects', 'together'=>true),
When I called $model->with('roles', 'projects')->findAll(), from the log, I could see that table UserProjectRole was used twice in the joins. I understand with my upper declarations, I cannot expect other result. Please show me how to correct the declarations.
Below is the example of the data and result I have got,
User (1, 'UA')
Project (1, 'PA') (2, 'PB')
Role (1, 'RA') (2, 'RB')
UserRoleProject (1, 1, 1) – userid, roleid, projectid
UserRoleProject (1, 2, 2)
It returns 4 rows:
1 1 1
1 1 2
1 2 1
1 2 2
While it should have only 2 rows in UserRoleProject
Thank you.