Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1397

Accesing a OneToMany relation with Child Classes and OneToOne relations.

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Invalid
    • Affects Version/s: 2.1, 2.1.1, 2.1.2
    • Fix Version/s: 2.1.2
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Ubuntu 10.10 64bit
      PHP 5.3.3
      MySQL 5.1.49
      Doctrine 2.1.2

      Description

      I am facing a small issue on Doctrine 2 that causes OneToOne relation needed to be part of the parent class. The error occurs when doing $content->getVersions() but not when doing $em->find("Model\Lantern\Content\Version", $id). The error message is:

      Warning: Undefined index: summary in ORM/UnitOfWork.php:2012
      Fatal error: Call to a member function setValue() on a non-object in ORM/UnitOfWork.php on line 2013
      

      Error replication:

      Simply by having a look at the model we can see what's causing the Bug, will avoid class annotations to make it simpler:

      class Content{
          /**
          * @OneToMany(targetEntity="Version", mappedBy="content")
          */
          private $versions;
      ...
      }
      
      class Version{
          /**
           * @ManyToOne(targetEntity="Content", inversedBy="versions")
           * @JoinColumn(name="content_id", referencedColumnName="content_id")
           */
          private $content;
      ...
      }
      
      class Article extends Version{
          /** @OneToOne(targetEntity="Model\Lantern\Content\Fieldset\Summary", mappedBy="version", cascade={"persist", "delete"}) */
          private $summary;  
      ...
      }
      
      class Summary{
          /**
           * @OneToOne(targetEntity="Model\Lantern\Content\Version", inversedBy="summary")
           * @JoinColumn(name="version_id", referencedColumnName="version_id")
           */
          private $version;    
      ...
      }
      

      As you can see, Article::$summary targets Summary::$version, but Summary::$version targets Version::$summary. This in OOP is valid as Version is contained inside Article, so doing a downcasting will get Article::summary.

      The reason I believe why using $em->find works is that $em->find already knows which child class is before doing map, and relations works fine.
      On the other hand, when doing $content->getVersions(), Content::$versions targets Version, and looks like Doctrine does not resolve which child class it before mapping OneToOne relationshipg.

      This bug doesn't occur with OneToMany or ManyToMany relationships.

        Activity

        Gabriel Brunacci created issue -
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Invalid [ 6 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 13051 ] jira-feedback [ 15043 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback [ 15043 ] jira-feedback2 [ 16907 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 16907 ] jira-feedback3 [ 19160 ]

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Gabriel Brunacci
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: