04.03 php
Matt
Note
Matt did not leave a note
  1. <?php
  2. /*
  3. For Containable to work I add:
  4. $Model->{$name};
  5. on line 338 of /cake/libs/model/behaviors/containable.php right before
  6. if (!isset($Model->{$name}) || !is_object($Model->{$name})) {
  7. Hack for now...there's probably a better way
  8. */
  9.  
  10. class AppModel extends Model {
  11.   var $actsAs = array('Containable');
  12.   var $recursive = -1;
  13.   var $__definedAssociations = array();
  14.   var $__loadAssociations = array('Aro', 'Aco', 'Permission');
  15.  
  16.   //back up all the defined associations before calling parent::__construct
  17.   //this way none of the related models are loaded.
  18.   function __construct($id = false, $table = null, $ds = null) {
  19.     if (!in_array(get_class($this), $this->__loadAssociations)) {
  20.       foreach($this->__associations as $association) {
  21.         foreach($this-> {$association} as $key => $value) {
  22.           $assocName = $key;
  23.  
  24.           if (is_numeric($key)) {
  25.             $assocName = $value;
  26.             $value = array();
  27.           }
  28.  
  29.           $value['type'] = $association;
  30.           $this->__definedAssociations[$assocName] = $value;
  31.           if (!empty($value['with'])) {
  32.             $this->__definedAssociations[$value['with']] = array('type' => 'hasMany');
  33.           }
  34.         }
  35.  
  36.         $this-> {$association} = array();
  37.       }
  38.     }
  39.  
  40.     parent::__construct($id, $table, $ds);
  41.   }
  42.  
  43.   function __get($name) {
  44.     if (empty($this->__definedAssociations[$name])) {
  45.       return false;
  46.     }
  47.  
  48.     $this->bind($name, $this->__definedAssociations[$name]);
  49.     return $this-> {$name};
  50.   }
  51. }
  52. ?>
Parsed in 0.050 seconds, using GeSHi 1.0.7.14

Modify this Paste