CakePHP Plugin - Loads model asssociations as needed.
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


 * CakePHP Lazy Loader Plugin
 * Copyright (c) 2009 Matt Curry
 * This is my second attempt at this.
 * The code posted by jose_zap (José Lorenzo -
 * on provided inspiration for this revised version
 * @author      Matt Curry <>
 * @license     MIT

/* Requirements */
PHP 5.1 or greater

/* Description */
The code is very beta.  Please give it a shot and let me know where you hit snags.  
I've tested it in basic app using Containable and it works great.  
It probably doesn't work with $recursive.

If you find a problem check out the unit tests and see if you can create a failing test case

/* Instructions */
1) Download the plugin to /app/plugins/lazy_loader

2) Put this either in your app_model.php or at the top of any model you want to use it:
   App::import('Model', 'LazyLoader.app_model');
3) Have your model extend LazyLoaderAppModel instead of AppModel
   class MyModel extends LazyLoaderAppModel {
4) For this to work for HATBM relationships you need to include the joinTable and associationForeignKey in the defination.
   This is because Cake uses the associated models to set the defaults for these.  So even if you are following the conventions, set these to avoid having the related model loaded.
   class Post extends LazyLoaderAppModel {
	   var $name = 'Post';
     var $hasAndBelongsToMany = array('Tag' => array('joinTable' => 'posts_tags', 'associationForeignKey' => 'tag_id'));