Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2297

Add ConstraintException for parent row

    Details

    • Type: New Feature New Feature
    • Status: Resolved
    • Priority: Trivial Trivial
    • Resolution: Won't Fix
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: ORM
    • Labels:
      None

      Description

      Currently there is no constraint check for entities that depends another one.
      I always check the dependencies using repository. Something like this:

      $childRepository = $em->getRepository('Child');
      $parent = $em->getReference('app:Parent', $id);
      $children = $childRepository->findBy(array('parent' => $parent));
      
      if ($children) {
          throw new Exception('You can not delete this record. There are records related');
      }
              
      $em->remove($parent);
      $em->flush();
      

      This exception could be thrown in $em->flush(); or could look like:

       
      try {
          $parentEntity = $em->gerReference('ParentEntity', $id);
          $em->remove($parentEntity);
          $em->flush();
      catch (SomeORMNamespace\ConstraintException $e) {
          echo $e->getMessage(); //outs: You cannot remove this entity. There is another one related.
      }
      

      I think this functionality could be implemented through metadata on any sides of the relationship or on the @Entity mapping.

      @Entity(children={'Child'}) //this is not a good attr name =)
      class Parent {}
      

      I know that is more app business logic related, but is it possible to implement this feature in next releases?

        Activity

        Daniel Lima created issue -
        Hide
        Benjamin Eberlei added a comment -

        This is responsiblity of the the application developer.

        You can implement this generically using parts of the API shown below:

        $metadata = $entityManager->getClassMetadata("ClassName");
        
        foreach ($metadata->associationMappings as $assoc) {
           if ($assoc['type'] & ClassMetadata::TO_ONE) {
              
           }
        }
        
        Show
        Benjamin Eberlei added a comment - This is responsiblity of the the application developer. You can implement this generically using parts of the API shown below: $metadata = $entityManager->getClassMetadata( "ClassName" ); foreach ($metadata->associationMappings as $assoc) { if ($assoc['type'] & ClassMetadata::TO_ONE) { } }
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Won't Fix [ 2 ]

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2297, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Daniel Lima
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: