Thanks for the response. You are correct - the enduserid field is in the RoleUser join table.
On Sunday, December 9, 2012 5:54:26 PM UTC-5, cricket wrote: > > You shouldn't need to use loadModel() if the associations are set up > correctly. > > When you call $this->Auth->user() with no params you get an array with > all data. I don't recall how deeply that goes. Try this in your > login() action, or some other action that requires authentication: > > die(debug($this->Auth->user())); > > If Auth doesn't make the Role data available you could fetch it for > that User and then check the result. But it's not clear where this > enduserid column resides. It's in the join table? > > On Sun, Dec 9, 2012 at 12:10 PM, Md <[email protected] <javascript:>> > wrote: > > Hi there, > > > > I have a small application that has three tables. users, roles, and > > role_users. The role_users table is a join table as a user can have > > multiple roles. In my UsersController class I am trying to get a count > for > > the number of roles the current user has where there is a enduserid = 1. > > > > public function hasEndUser(){ > > > > $this->loadModel('RoleUser'); > > > > $userId = $this->Auth->user('id'); > > > > $conditions = array('RoleUser.user_id ='=>$userId,'RoleUser.enduserid > > ='=>1); > > > > $result = $this->RoleUser->find('count',$conditions); > > > > debug($result); > > > > } > > > > For whatever reason, this is the SQL that I am getting back: > > > > SELECT COUNT(*) AS `count` FROM `bridges`.`role_users` AS `RoleUser` > LEFT > > JOIN `bridges`.`users` AS `User` ON (`RoleUser`.`user_id` = `User`.`id`) > > LEFT JOIN `bridges`.`roles` AS `Role` ON (`RoleUser`.`role_id` = > > `Role`.`id`) WHERE 1 = 1 > > > > > > As a result, I am also getting the wrong count. > > > > -- > > 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 [email protected]<javascript:>. > > > To unsubscribe from this group, send email to > > [email protected] <javascript:>. > > Visit this group at http://groups.google.com/group/cake-php?hl=en. > > > > > -- 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 [email protected]. To unsubscribe from this group, send email to [email protected]. Visit this group at http://groups.google.com/group/cake-php?hl=en.
