Containable Behavior
Posted on | November 23, 2008 | No Comments
Cakephp Beta 1.2 RC has a new core behavior called Containable. This behavior is used to setup relationship between models. Instead of using bindable, I am now using the Containable behavior, which makes things easier.
You can leave the recursive = -1 out of your codes when using this behavior.
Get it working
Define $actAs variable in your model:
$actAs = array('Containable');
or on-the-fly
$this->Feature->Behaviors->attach('Containable');
Get your results
$this->paginate = array('contain' => array('Attachment.filename', 'User'),'limit' => 20, 'order' => array('Feature.created' => 'DESC'));
What this code does is filter only fields specified in “contains”, retrieves only 20 records “limit”, in order specified by “order”.
Replace $this->Feature->recursive = -1; by setting the contain to false
$this->paginate = array('contain' => false,'limit' => 20, 'order' => array('Feature.created' => 'DESC'));
Category: Cakephp
Comments
Leave a Reply




















