tags:

views:

13

answers:

1

I'm using CakePHP here. Let's say I have 3 groups of user, namely:

  1. Super Admin
  2. Admin
  3. Customer

and this scenario has been setup using ACL.

Now, how do I return only users that belong to a particular group? e.g. Find all Customer only

I am able to do this using pure SQL statement:

SELECT *
FROM `users`
WHERE `id`
IN (
SELECT foreign_key
FROM `aros`
WHERE `parent_id` =3
)

How do I do it in CakePHP way of using $this->Model->find();?

A: 

The way is the same as in all find cases:

$users = $this->User->find('all', array('conditions'=>array('User.aro_id'=>3)));

Basically it depends from the relation, but as far I understand it's Group hasMany Users.

Nik
Thanks for the fast reply but, my ACL setup doesn't contain another table for Group. It's all defined in the aros.alias table. So it has no relation with Users table. That's why I can't seem to find a way to get only the users from a particular group in a straight forward way.
kenfai
Ok, but how Aro is related with Users?
Nik