I am having trouble returning a query.  I have the following setup

Users - users class of all users in the system.
Roles - roles class with a set of available roles.  E.g. teacher, student, 
tutor
RoleUsers - a mapping table between users and roles as a single user can 
have multiple roles.


My Users class has this

public $hasAndBelongsToMany = array(

        'Role' =>

            array(

                'className'              => 'Role',

                'joinTable'              => 'role_users',  //was roles_users

                'foreignKey'             => 'user_id',

                'associationForeignKey'  => 'role_id',

                'unique'                 => true)

);


My RolesUser class has this

public $belongsTo = array(

        'User' =>

            array(

                'className'              => 'User',

                'joinTable'              => 'users',  

                'foreignKey'             => 'user_id',

                'unique'                 => true),

         'Role' =>

            array(

                'className'              => 'Role',

                'joinTable'              => 'roles',  

                'foreignKey'             => 'role_id',

                'unique'                 => true)


I am now trying to query the user table to determine the students belonging 
to the logged in user (a teacher or tutor)


public function getStudents(){

$userId = $this->Auth->user('id'); 

$conditions = array('conditions' => array (array('Role.id =' => 75),  //75 
is the role for all students

array ('RoleUser.id = ' => $userId)));  //this is the current logged in user

$result = $this->User->find('all',$conditions);

debug($result);


In the top of my UsersController, I have:

public $uses = array('Role', 'RoleUser');


When I run the function getStudents above, I am getting *Error: *Call to a 
member function find() on a non-object


);

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com.
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.


Reply via email to