public
Description: CakePHP Lazy Load implementation
Homepage: http://rafaelbandeira3.wordpress.com/2008/11/21/lazy-loader-behavior-what-you-need-when-you-need-the-way-you-want/
Clone URL: git://github.com/rafaelbandeira3/lazy_loading.git
Fri Dec 19 09:50:24 -0800 2008
commit  d20b51a817a3c0fb05858f1191635d0b2901d430
tree    54bc657f3f5452826a4f60eecced2cb24d70019e
parent  419f6593a6915619c54ef7add94bc26f09ee96d4
name age message
file README Fri Dec 19 09:44:31 -0800 2008 initial commit [rafaelbandeira3]
directory models/ Fri Dec 19 09:44:31 -0800 2008 initial commit [rafaelbandeira3]
directory tests/ Fri Dec 19 09:50:24 -0800 2008 correcting test case to use the plugin prefix [rafaelbandeira3]
README
LazyLoading Plugin
CakePHP 1.2 Plugin - PHP 5 only

LazyLoaderBehavior - What you need, When you need, The way you want.

Enables easy access to related data through a Lazy Load¹ like interface,
mapping methods named as "get<AssociatedModelName>" or "get_<associated_model_name>",
to fetch related data and return. Can receive a string as first parameter to set the find type² to be 
used in the operation. If the associated model to be used in the operation is related as
"belongsTo" or "hasOne", a boolean TRUE can be passed as first or second param to force method to return
the associated model instance setted with the related record data.
¹ - http://en.wikipedia.org/wiki/Lazy_loading
² - http://cakebaker.42dh.com/2008/09/23/an-alternative-way-to-define-custom-find-types/

Usage:
Notice that the method requires the Model to be instantiated with an exitant record id, and the
related model to be binded during the process.

Project belongsTo Company
Project hasOne Owner
Project hasMany Task
Project hasAndBelongsToMany User
Projects hasMany FeaturesProblemsAndBugs

$Project->getCompany(); // returns data of the related Company
$Project->getOwner(); // returns data of the related Owner
$Project->getTasks(); // returns related tasks list
$Project->getUsers(); // returns related users list
$Project->getTasks('all'); // returns related tasks data
$Project->getTasks('closed'); // returns related tasks fetched by a Task::find('closed') operation
$Project->getCompany(true); // returns Company model instance setted with related record data
$Project->getTask(); // error as Project has many Task not just one
$Project->get_tasks(); // works too
$Project->get_features_problems_and_bugs(); // works too

Although not recommended can also be through the behavior method:
- notice that it would break extensibility and flexibility of overriding to customization on Model side.
$Project->lazyLoad('Company');
$Project->lazyLoad('Tasks');

--------------------------------------------------------

RafaelBandeira <rafaelbandeira3 (at) gmail (dot) com>
http://rafaelbandeira3.wordpress.com/

Licensed under The MIT License
Redistributions of files must retain the above copyright notice.