Skip to content

Instantly share code, notes, and snippets.

@michaeltwofish
Created June 9, 2011 07:37
Show Gist options
  • Save michaeltwofish/1016261 to your computer and use it in GitHub Desktop.
Save michaeltwofish/1016261 to your computer and use it in GitHub Desktop.
Custom lithium finder
<?php
// Create a finder for popular tags
static::finder('popular', function($self, $params, $chain) {
$params['options']['joins'] = array(new Query(array(
'source' => 'candidate_tags',
'constraint' => array ('Tag.id' => 'candidate_tags.tag_id'),
'group' => 'tag_id',
)));
$params['options']['fields'] = array('tag_id as id', 'name', 'client_id', 'count(tag_id) as theCount');
$params['options']['order'] = 'theCount DESC';
$params['options']['group'] = 'GROUP BY candidate_tags.tag_id';
return $chain->next($self, $params, $chain);
});
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment