Your fieldnames and table definition don't match, but I assume
user_id_to/from is meant to be profile_id_to/from.

As to your problem, if you're echoing $profile['Comment'][]
['profile_id_from'], then naturally it's going to be the value from
Comment.profile_id_from.

If your recursive is set to 1, then cake should fetch the associated
profile of each comment. Check the find results with debug($profile).
If it's not there, then try 'recursive'=>2 in your find query.

Personally, I'd do a join, because the way Cake normally fetches
associated data seems to be a bit inefficient--or at least uses more
queries than necessary. But if you're not concerned about
optimization, just using the right recursive mode should do it. But
you'll still need to output $profile['Comment'][]['Profile']['name'],
or something to that extent, in order to get the name of the person
who wrote the comment. echo() isn't a cake function. It won't
automagically print the display name like $form->input() does.

On Apr 25, 4:48 am, Indian Baker <[email protected]> wrote:
> Hi,
> I need to create a comments sections for user profiles with the
> following table design
>
> Comment.id
> Comment.user_id_to
> Comment.user_id_from
>
> So when I'm viewing a Users profile I can see all the comments made on
> that profile.
> I'm stumped on how to build the model what I have right now on the
> users model is
>
> --------------Model--------------------
> class Profile extends AppModel {
>         var $name = 'Profile';
>         var $displayField = 'name';
>
> var $hasMany = array(
>                   'Comment'=>array(
>                 'className'=>'Comment',
>                  'foreignKey' => 'profile_id_to',
>                  'order' => 'Comment.date DESC',
>                 'limit' => '5',
>                 'fields' => array(
>                                 'Comment.profile_id_from', 
> 'Comment.description',
>                         )
> )
>
> --------------------------Controller ---------------------------------
>
> $this->Profile->find('first',array('conditions'=>array('Profile.id'=>
> $id)));
>
> ----------------------------View-------------------------------------
>
> foreach ($profile['Comment'] as $index => $comment) {
>
>                 echo "Name:". $comment['profile_id_from']."<br/>";
>                         echo $comment['description']."<br/>";
>
>         }
>
> All the comments under a profile show up just fine but instead of
> showing the Profile Name its shows me the profile_id_from value.. any
> idea how to get it to show the name
>
> Thanks in advance
> IB
>
> Check out the new CakePHP Questions sitehttp://cakeqs.organd help others with 
> their CakePHP related questions.
>
> 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 
> athttp://groups.google.com/group/cake-php?hl=en

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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