If you have User associated, you might already have the info in $this-
>data.
Here's an example:
class Message extends AppModel
{
var $name = 'Message';
var $belongsTo = array('User');
}
class MessagesController extends Appcontroller
{
function view($id)
{
$result = $this->Message->find(array('Message.id' => $id),
null, null, true); // recursive set to true, will fetch associations
$message_title = $result['Message']['title'];
$sender = $result['User']['username'];
}
}
On 20 Juli, 12:34, CakeSpork <[EMAIL PROTECTED]> wrote:
> Hi,
> I have a pretty basic question that I've still not gotten through to
> after these past weeks of plunging into Cake and I thought I might
> find some help here. How do you guys mostly go around to finding the
> associated User to a user_id? I seem to do this so often that at the
> very least uses('User') along with $this->User->findById seems very
> insufficient (ie. lengthen loading times).
>
> These models are obviously already associated to the User models with,
> for example, Message belongsTo Sender with foreign ID sender_id and
> Message belongsTo Receiver, foreign ID user_id. And of course, User
> hasMany Message. So, how _should_ I ask up more info. about these
> users?
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---