protected function _validateDelete($entity)
    {
        $relationships = $entity->getEntityDescription()->getRelationships();

        foreach ($relationships as $name => $relationship) {
            if ($relationship->isManyToOne() || $relationship->isManyToMany()) {
                continue;
            }

            if ($relationship->getDeleteRule()    ==  AnDomain::DELETE_CASCADE
                 || $relationship->getDeleteRule() ==  AnDomain::DELETE_DESTROY
            ) {
                $property = $relationship->getName();
                $entities = $entity->getData($property);

                if (!$entities) {
                    continue;
                }
                //someone else is responsible for deleteing the relations
                //good for mass deletion. i.e. node and edges
                if ($relationship->getDeleteRule() == AnDomain::DELETE_IGNORE) {
                    continue;
                } elseif ($relationship->getDeleteRule() == AnDomain::DELETE_DESTROY) {
                    if ($relationship->isOneToOne()) {
                        $query = AnDomainQuery::getInstance($relationship->getChildRepository(), $entities->getIdentityId());
                    } else {
                        $query = $entities->getQuery();
                    }

                    $relationship->getChildRepository()->destroy($query);
                    continue;
                } else {
                    if ($relationship->isOneToOne()) {
                        $entities = array($entities);
                    }

                    foreach ($entities as $entity) {
                        //if the cascading fails for the related entities then
                        //nullify the property in the failed entity 
                        if (!$entity->delete() && $entity->getObject()) {
                            $entity->set($relationship->getChildKey(), null);
                        }
                    }
                }
            } elseif ($relationship->getDeleteRule() == AnDomain::DELETE_DENY) {
                //don't state change if there at least one entity left
                $count = $entity->getData($relationship->getName())->limit(0, 0)->getTotal();

                if ($count > 0) {
                    $entity->reset();

                    return false;
                }
            } elseif ($relationship->getDeleteRule() == AnDomain::DELETE_NULLIFY) {
                //@TODO you should set the values to null directly rather
                //then instantiating them
                $entities = $entity->getData($relationship->getName())->fetchSet();
                $property = $relationship->getChildKey();
                foreach ($entities as $entity) {
                    $entity->set($property, null);
                }
            }
        }

        return true;
    }
protected function _validateDelete($entity)
    {
        $relationships = $entity->getEntityDescription()->getRelationships();

        foreach ($relationships as $name => $relationship) {
            if ($relationship->isManyToOne() || $relationship->isManyToMany()) {
                continue;
            }

            if ($relationship->getDeleteRule()    ==  AnDomain::DELETE_CASCADE
                 || $relationship->getDeleteRule() ==  AnDomain::DELETE_DESTROY
            ) {
                $property = $relationship->getName();
                $entities = $entity->getData($property);

                if (!$entities) {
                    continue;
                }
                //someone else is responsible for deleteing the relations
                //good for mass deletion. i.e. node and edges
                if ($relationship->getDeleteRule() == AnDomain::DELETE_IGNORE) {
                    continue;
                } elseif ($relationship->getDeleteRule() == AnDomain::DELETE_DESTROY) {
                    if ($relationship->isOneToOne()) {
                        $query = AnDomainQuery::getInstance($relationship->getChildRepository(), $entities->getIdentityId());
                    } else {
                        $query = $entities->getQuery();
                    }

                    $relationship->getChildRepository()->destroy($query);
                    continue;
                } else {
                    if ($relationship->isOneToOne()) {
                        $entities = array($entities);
                    }

                    foreach ($entities as $entity) {
                        //if the cascading fails for the related entities then
                        //nullify the property in the failed entity 
                        if (!$entity->delete() && $entity->getObject()) {
                            $entity->set($relationship->getChildKey(), null);
                        }
                    }
                }
            } elseif ($relationship->getDeleteRule() == AnDomain::DELETE_DENY) {
                //don't state change if there at least one entity left
                $count = $entity->getData($relationship->getName())->limit(0, 0)->getTotal();

                if ($count > 0) {
                    $entity->reset();

                    return false;
                }
            } elseif ($relationship->getDeleteRule() == AnDomain::DELETE_NULLIFY) {
                //@TODO you should set the values to null directly rather
                //then instantiating them
                $entities = $entity->getData($relationship->getName())->fetchSet();
                $property = $relationship->getChildKey();
                foreach ($entities as $entity) {
                    $entity->set($property, null);
                }
            }
        }

        return true;
    }
protected function _validateDelete ( $ entity ) { $ relationships = $ entity -> getEntityDescription ( ) -> getRelationships ( ) ; foreach ( $ relationships as $ name => $ relationship ) { if ( $ relationship -> isManyToOne ( ) || $ relationship -> isManyToMany ( ) ) { continue ; } if ( $ relationship -> getDeleteRule ( ) == AnDomain :: DELETE_CASCADE || $ relationship -> getDeleteRule ( ) == AnDomain :: DELETE_DESTROY ) { $ property = $ relationship -> getName ( ) ; $ entities = $ entity -> getData ( $ property ) ; if ( ! $ entities ) { continue ; } //someone else is responsible for deleteing the relations //good for mass deletion. i.e. node and edges if ( $ relationship -> getDeleteRule ( ) == AnDomain :: DELETE_IGNORE ) { continue ; } elseif ( $ relationship -> getDeleteRule ( ) == AnDomain :: DELETE_DESTROY ) { if ( $ relationship -> isOneToOne ( ) ) { $ query = AnDomainQuery :: getInstance ( $ relationship -> getChildRepository ( ) , $ entities -> getIdentityId ( ) ) ; } else { $ query = $ entities -> getQuery ( ) ; } $ relationship -> getChildRepository ( ) -> destroy ( $ query ) ; continue ; } else { if ( $ relationship -> isOneToOne ( ) ) { $ entities = array ( $ entities ) ; } foreach ( $ entities as $ entity ) { //if the cascading fails for the related entities then //nullify the property in the failed entity  if ( ! $ entity -> delete ( ) && $ entity -> getObject ( ) ) { $ entity -> set ( $ relationship -> getChildKey ( ) , null ) ; } } } } elseif ( $ relationship -> getDeleteRule ( ) == AnDomain :: DELETE_DENY ) { //don't state change if there at least one entity left $ count = $ entity -> getData ( $ relationship -> getName ( ) ) -> limit ( 0 , 0 ) -> getTotal ( ) ; if ( $ count > 0 ) { $ entity -> reset ( ) ; return false ; } } elseif ( $ relationship -> getDeleteRule ( ) == AnDomain :: DELETE_NULLIFY ) { //@TODO you should set the values to null directly rather //then instantiating them $ entities = $ entity -> getData ( $ relationship -> getName ( ) ) -> fetchSet ( ) ; $ property = $ relationship -> getChildKey ( ) ; foreach ( $ entities as $ entity ) { $ entity -> set ( $ property , null ) ; } } } return true ; }
Validates and apply delete rules for an entity.

@param $entity
Validates and apply delete rules for an entity .