On Dec 18, 8:10 pm, brian <[email protected]> wrote:
> Andy Dawson's PolymorphicBehavior seems like the perfect answer to a
> problem I have but I'm having trouble implementing it. My situation is
> that I have  a User model, then several different models which a user
> can "be" ie. 'Organization', 'Student', etc. So, I've tried doing
> this:
>
> users table:
> id
> created
> modified
> model
> foreign_key
>  -- etc.
>
> class User extends AppModel
> {
>         var $name = 'User';
>         var $actsAs = array('Polymorphic');
>
> }
>
> class Admin extends AppModel
> {
>         var $name = 'Admin';
>
>     var $hasOne = array(
>         'User' => array(
>             'className' => 'User',
>             'foreignKey' => 'foreign_key',
>             'conditions' => array('User.model' => 'Admin'),
>             'dependent' => true
>         )
>     );
>
> }
>
> UsersController:
>
> $user = $this->User->findByEmail($this->data['User']['email']);
> debug($user); exit;
>
> All I see is an array for 'User'.
>
> I've verified that the DB tables have the correct information.
>
> Am I looking at this the wrong way? In Andy's article[1] he uses the
> example of a Note class which can belongTo several others. My
> situation is a bit different, though it seems much closer to how I
> understood polymorphic classes to work.
>
> [1]http://bakery.cakephp.org/articles/view/polymorphic-behavior

It's for polymorphic associations rather than polymorphic objects.
Although you can use it for what you're describing, it was written for
things like notes.

Try the active-dev version:
http://trac.assembla.com/mi/browser/branches/base/models/behaviors/polymorphic.php#L105

you'd see a $data['User']['Admin'][ full admin data ] for an admin
user.

hth

AD
--~--~---------~--~----~------------~-------~--~----~
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]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to