Its a basic function (notice I cant use containable on GamesSystem to
get Game, else it would fail):

/**
 * Gets the most played games (for now based on games_system_id)
 * @param int $limit
 * @return array
 */
function getMostPlayedGames($limit = 5) {
        $games = $this->find('all', array(
                'fields' => array('TeamsGame.*', 'GamesSystem.*', 'COUNT
(UsersGame.games_system_id) AS TeamsGame__totalTeams'),
                'contain' => array('GamesSystem'),
                'group' => array('TeamsGame.games_system_id'),
                'order' => 'COUNT(*) DESC',
                'limit' => $limit
        ));

        if (!empty($games)) {
                foreach ($games as &$game) {
                        $data = ClassRegistry::init('Game')->find('first', 
array(
                                'fields' => array('Game.name', 'Game.id', 
'Game.slug'),
                                'conditions' => array('Game.id' => 
$game['GamesSystem']
['game_id'])
                        ));

                        $game = array_merge($game, $data);
                }
        }

        return $games;
}

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to