php - CakePHP: How to find columns ordered by number of related models? -


i hope able me. have 2 tables websites , likes. each website has likes. can't figure out how can websites ordered number of likes. sounds pretty basic me failed find solution...

something following tried last (actsas containable in model available):

$this->paginate = array('contain' => array(     'like' => array(          'order' => array('count(like.id) desc')     ) )); $this->set('websites', $this->paginate()); 

could me please?

cheers. andreas

// update found solution. use countercache. interested should countercache - cache count() here , thats code

$this->paginate = array(     'order' => array('like_count' => 'desc'),     'limit' => 15 ); $this->set('websites', $this->paginate()); 

i found solution. use countercache. interested should read countercache - cache count() here , thats code

$this->paginate = array(      'order' => array('like_count' => 'desc'),      'limit' => 15 ); $this->set('websites', $this->paginate()); 

Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -