>
> could you help me how to fetch users from same company if I know
> userId?
>
> SELECT u.* FROM users u
> JOIN companies c ON u.companyId = c.id
> JOIN users u2 ON u2.companyId = c.id
> WHERE u2.id = $userId
I would honestly use the SQL query you show above.
To do it with the Table interface:
$user = new User();
$usersFromSameCompany = $user->find($userId)->current()
->findParentRow('Company')
->findDependentRowset('User');
(this is not tested)
Regards,
Bill Karwin
没有评论:
发表评论