Show
Ignore:
Timestamp:
05/12/08 14:02:03 (7 months ago)
Author:
aarkerio
Message:

Improved helper

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/app/app_model.php

    r339 r474  
    11<?php 
     2/**  
     3*   @author: Manuel Montoya  
     4*   Chipotle SoftwareTM 2002-2008   
     5*   GPLv3   
     6**/ 
    27class AppModel extends Model{ 
    38  
     
    3540        ( 
    3641                array($this->assocs[$assoc]['type'] => 
    37             array($assoc => $this->assocs[$assoc]))); 
    38             } 
    39      }  
     42            array($assoc => $this->assocs[$assoc])) 
     43            ); 
     44      } 
     45 } 
     46 
     47/**  
     48*   Unbinds all unneeded associations   
     49*   @author: Oth aka KrazyLegs 
     50*   @reference: http://othy.wordpress.com/2006/06/03/unbind-all-associations-except-some/  
     51**/ 
     52 
     53public function unbindAll($params = array()) 
     54{ 
     55  foreach($this->__associations as $ass) // this array returns hasOne, HasMany, etc    
     56  { 
     57     if (!empty($this->{$ass}))  // if hasMany assos exist, if HasOne exist, etce 
     58     { 
     59        $this->__backAssociation[$ass] = $this->{$ass}; 
     60 
     61    if ( isset($params[$ass]) ) 
     62    { 
     63           foreach ( $this->{$ass} as $model => $detail ) 
     64       { 
     65          if (!in_array($model,$params[$ass])) 
     66          { 
     67            $this->__backAssociation = array_merge($this->__backAssociation, $this->{$ass}); 
     68            unset($this->{$ass}[$model]); 
     69          } 
     70       } 
     71        } 
     72        else 
     73        { 
     74          $this->__backAssociation = array_merge($this->__backAssociation, $this->{$ass}); 
     75          $this->{$ass} = array(); 
     76        } 
     77       } 
     78     } 
     79    return true; 
     80  }   
    4081} 
    4182?>