В Модели Пользователя связываю работников и пользователей
Код: Выделить всё
class User extends CActiveRecord {
...
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'partnerships' => array(self::HAS_MANY,'Partnership','user_id','joinType'=>'INNER JOIN'),
'employees' => array(self::HAS_MANY, 'User', array('employee_id'=>'id'),'through'=>'partnerships','joinType'=>'INNER JOIN'),
);
}
...
}
Код: Выделить всё
class Partnership extends CActiveRecord
{
...
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'employee' => array(self::BELONGS_TO, 'User', 'employee_id'),
'user' => array(self::BELONGS_TO, 'User', 'user_id'),
);
}
...
}
Код: Выделить всё
public function listUserWorkers($userId) {
$user = User::model()->findByPk($userId);
return $user->employees;
}
Код: Выделить всё
echo User::model()->listUserWorkers(25);