I'm guessing you've got something like:

users
---------
id
name
referrer_id
...

Then simply setup a new association in your users model.


<?php
class User extends AppModel {

        var $name = 'User';

        var $belongsTo = array(
                        'Referrer' => array('className' => 'User',
                                                                'foreignKey' => 
'referrer_id',
                                                                'fields' => 
array('id','name'),
                        )
        );

}
?>


Then in your view you would do something like:

<?php echo $user['Referrer']['name'] ?>

Cheers,
Adam


On Mar 6, 4:33 pm, jaypee <[EMAIL PROTECTED]> wrote:
> I have a self-join (belongsTo) within a users table to track who
> referred who.
>
> I have managed to produce the code to associate the user to referrer,
> however, i was wondering how in the add and edit views i can display
> the user's name instead of their id (which is the foreignKey)?
>
> I have tried adding to the $form->input() but I am not sure if I
> should adding the code to fetch the names of the users (who are
> generated within the referrer field) along with their id, in the
> controller or the view file/s?
>
> Any ideas would be appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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