Friday, October 26, 2012

HABTM and user login

I have a User model to use built-in authentication. The model has several $hasOne relationships and all linked models get saved automatically into session, which is great because I can call AuthComponent::user() whenever I need to perform an action based on user data.

Now, I've added a $hasAndBelongsToMany relationship to indicate that a user can belong to zero or more groups. However, information about the Group model doesn't show up anywhere in the Auth component. I can definitively perform a manual User->find() and groups will be there but AuthComponent::user() does not contain group information. I've tried everything I could think of, including the contain option. I know I'm using contain right because it makes valid models appear and it complains for non-existant models, but Group is simply ignored.

In the end I had to write a hack in my login function: make a manual find() and incorporate the 'Group' key to session data.

Is this a known limitation?

--
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+unsubscribe@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
 
 

No comments: