Skip to content

lorenzo/lazy_loader

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 

Repository files navigation

/*
 * CakePHP Lazy Loader Plugin
 * Copyright (c) 2009 Matt Curry
 * http://www.pseudocoder.com/archives/2009/04/27/github-updates
 *
 * This is my second attempt at this.
 * The code posted by jose_zap (José Lorenzo - http://joselorenzo.com.ve/)
 * on bin.cakephp.org provided inspiration for this revised version
 * http://bin.cakephp.org/saved/39855
 *
 * @author      Matt Curry <matt@pseudocoder.com>
 * @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'));
   }

About

CakePHP Plugin - Loads model asssociations as needed.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%