Hi, i have 3 tables Users, Improvements and Bookmarks a user can
bookmark one or more improvements. The bookmark table holds the
user_id and improvement_id. When i'm pulling the information (query
below), i also need to show the author of the improvements username.
Is it possible to call a function in afterFind of the appropriate
model which will retrieve the username for each improvement record
e.g.
function getUsername($user_id){
$conditions = array(
'conditions' => array('User.user_id' =>
$user_id),
'fields' => array('User.id', 'User.username'),
'order' => null,
'recursive' => -1,
'limit' => 1
);
return $this->set('post_author',
$this->User->find('first',
$conditions));
}
SELECT `Bookmark`.`id`, `Bookmark`.`user_id`,
`Bookmark`.`improvement_id`, `User`.`id`, `User`.`username`,
`Improvement`.`id`, `Improvement`.`user_id`, `Improvement`.`title`,
`Improvement`.`description`, `Improvement`.`created` FROM `bookmarks`
AS `Bookmark` LEFT JOIN `users` AS `User` ON (`Bookmark`.`user_id` =
`User`.`id`) LEFT JOIN `improvements` AS `Improvement` ON
(`Bookmark`.`improvement_id` = `Improvement`.`id`) WHERE
`Bookmark`.`user_id` = 12
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---