| 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 | |
| | 53 | public 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 | } |