Complicated MANY_MANY relationship question

Hello,

I’m new to Yii, so please be explicit about what to change and where to change it.

I have three tables, and for simplicity’s sake I’ll call them:

  1. Departments

  2. Employees

  3. Commendations

The idea is that an employee can be in a department and an employee can get commendations (e.g. ‘top flight employee’, ‘exemplary manager’, etc.).

I already have these relations defined in the employees model:


'department' => array(self::BELONGS_TO, 'Department', 'deptID'),

'commendations' => array(self::MANY_MANY, 'Commendation', 'Commendation_Employee(employeeId, commendationId)'),

And these relations defined in the departments model:


'employees' => array(self::HAS_MANY, 'Employees', 'deptId')

Now I want to create a connection between Departments and Commendations. The returned list should be a distinct list of the commendations received by employees within the department.

Any thoughts on how to declare this relationship in Departments?

I got it: http://www.yiiframework.com/doc/guide/1.1/en/database.arr#relational-query-with-through