Customizing mysql query of a bound model

I had a hasAndBelongsToMany binding in my Charity Model as i normally would need all the “Causes” available along with Charity information and vice-versa. At one place i needed a specific number of “Causes” picked randomly from the database table. To make this work i had to add following two lines just before the $this->Charity->find call in my controller action:

$this->Charity->hasAndBelongsToMany['Cause']['limit']=5;
$this->Charity->hasAndBelongsToMany['Cause']['order']='rand()';

and i was done.

Does someone has a better solution? Please suggest.

Leave a Reply

Your email address will not be published.