예제 #1
0
 private function __deleteAssociationById(PersistentObject $object, AssociationMap $associationMap, $id, &$commands, ClassMap $classMap)
 {
     $toAttributeMap = $associationMap->getToAttributeMap();
     $fromAttributeMap = $associationMap->getFromAttributeMap();
     if (!is_array($id)) {
         $id = array($id);
     }
     if ($associationMap->getCardinality() == 'oneToOne') {
         if ($associationMap->isInverse()) {
             // obtem o objeto referenciado
             $refObject = $object->get($associationMap->getName());
             $refObject->setAttributeValue($toAttributeMap, NULL);
             $this->_saveObject($refObject, $associationMap->getToClassMap(), $commands);
         } else {
             // se a associação é direta, atualiza o próprio objeto
             $object->setAttributeValue($fromAttributeMap, NULL);
             $this->_saveObject($object, $classMap, $commands);
         }
     } elseif ($associationMap->getCardinality() == 'oneToMany') {
         $refObject = $associationMap->getToClassMap()->getObject();
         $commands[] = $associationMap->getUpdateStatementId($object, $id, NULL);
     } elseif ($associationMap->getCardinality() == 'manyToMany') {
         $commands[] = $associationMap->getDeleteStatementId($object, $id);
     }
     $associationMap->setKeysAttributes();
     $this->__retrieveAssociation($object, $associationMap, $classMap);
 }