Changeset 1254

Show
Ignore:
Timestamp:
02/25/09 06:20:13 (1 year ago)
Author:
bermi
Message:

Adding dependency control on belongs to associations

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/AkActiveRecord/AkAssociations/AkBelongsTo.php

    r468 r1254  
    282282        return true; 
    283283    } 
     284     
     285    function ___afterDestroy(&$object) 
     286    { 
     287        $success = true; 
     288        $associated_ids = $object->getAssociatedIds(); 
     289        foreach ($associated_ids as $associated_id){ 
     290            if( isset($object->$associated_id->_associatedAs) && 
     291            $object->$associated_id->_associatedAs == 'belongsTo' && 
     292            $object->$associated_id->getAssociationOption('dependent')){ 
     293                if ($object->$associated_id->getType() == 'belongsTo'){ 
     294                    $object->$associated_id->load(); 
     295                } 
     296                if(method_exists($object->$associated_id, 'destroy')){ 
     297                    $success = $object->$associated_id->destroy() ? $success : false; 
     298                } 
     299            } 
     300        } 
     301        return $success; 
     302    } 
     303     
     304     
    284305} 
    285306