Bindable Behavior
This behavior allows you to specify which models you are interested in when performing a find operation on a model that has relationships with other models. Simply put, it avoids you having to deal with subsequent calls to unbindModel and needing to set the right recursivity to avoid getting back model information which you may not be interested in at the time of a find call. It adds performance to your application (by avoiding needless database queries) and saves your precious coding time.
Quick Introduction
Say we are querying the Article model to look for all articles, and we want to obtain for every article the User who created it (together with its Profile), the Category on which the articles is located (but just the fields slug & name of the categories, we’re not really interested on other fields), the Comments for the article, and the User who created each Comment. Quite a bit of code in standard CakePHP unbindModel / bindModel operations. With Bindable Behavior, that would just be:
$articles = $this->Article->find('all', array('restrict' => array(
'User' => 'Profile', 'Category' => array('slug', 'name'), 'Comment' => 'User'
)));
It’s that easy! And you can take this even further, by changing binding parameters on the fly. Go ahead and read the tutorial at the bakery to learn all there is to learn.
Download
To download Bindable Behavior and other Cake Syrup ingredients go to the download page.
