Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1176

Error on proxy loading with foreign Key

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 2.1
    • Fix Version/s: 2.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Doctrine 2.1Beta

      Description

      Look at this thread:http://groups.google.com/group/doctrine-user/browse_thread/thread/2a03a6aea43428d6

      This entity class configuration:

      class IndividualsStatus
      {
          /**
           * @var Individuals
           *
           * @Id
           * @ManyToOne(targetEntity="Individuals", inversedBy="diagnosers", cascade={"persist","refresh","remove"})
           * @JoinColumns({
           *   @JoinColumn(name="individuals_id", referencedColumnName="id")
           * })
           */
          private $individuals;
      
          /**
           * @var Diagnosers
           *
           * @Id
           * @ManyToOne(targetEntity="Diagnosers", inversedBy="individuals", cascade={"persist","refresh"})
           * @JoinColumns({
           *   @JoinColumn(name="diagnosers_id", referencedColumnName="id")
           * })
           */
          private $diagnosers;
      
          /**
          * @var smallint $status
          *
          * @Column(name="status_individuals", type="smallint")
          */
          private $statusIndividuals;
      
          [...]
      }
      
      class Individuals
      {
          /**
           * @var Users
           *
           * @OneToOne(targetEntity="Users", cascade={"persist","detach","merge","refresh","remove"}, orphanRemoval=true)
           * @JoinColumns({
           *   @JoinColumn(name="users_id", referencedColumnName="id", unique=true)
           * })
           */
          private $users;
      
          /**
           * @var Advertisements
           *
           * @OneToMany(targetEntity="Advertisements", mappedBy="individuals")
           */
          private $advertisements;
      
          /**
           * @var IndividualsStatus
           *
           * @OneToMany(targetEntity="IndividualsStatus", mappedBy="individuals", cascade={"refresh", "remove", "persist"})
           * @joinColumns({
           *   @JoinColumn(name="individuals_id", referencedColumnName="id")
           * })
           */
          private $diagnosers;
      
        [...]
      }
      
      class Diagnosers
      {
          /**
           * @var Users
           *
           * @OneToOne(targetEntity="Users", cascade={"persist","remove","detach","merge","refresh"})
           * @JoinColumns({
           *   @JoinColumn(name="users_id", referencedColumnName="id", unique=true)
           * })
           */
          private $users;
      
          /**
           * @var Pros
           *
           * @OneToOne(targetEntity="Pros", cascade={"persist","remove","detach","merge","refresh"})
           * @JoinColumns({
           *   @JoinColumn(name="pros_id", referencedColumnName="id", unique=true)
           * })
           */
          private $pros;
      
          /**
           * @var Reports
           *
           * @OneToMany(targetEntity="Reports", mappedBy="diagnosers", cascade={"refresh", "remove"})
           */
          private $reports;
      
          /**
           * @var IndividualsStatus
           *
           * @OneToMany(targetEntity="IndividualsStatus", mappedBy="diagnosers", cascade={"refresh", "remove", "persist"})
           * @joinColumns({
           *   @JoinColumn(name="diagnosers_id", referencedColumnName="id")
           * })
           */
          private $individuals;
      }
      

      Note that in individuals, the relation called "Diagnosers" refered to IndividualsStatus entity.
      Note that in diagnosers, the relation called "Individuals" refered to IndividualsStatus entity.

      When I execute this DQL request:
         $qb->select(array('i', 'iss', 'u')) 
                 ->from('IndividualsStatus', 'iss') 
                 ->join('iss.individuals', 'i') 
                 ->join('i.users', 'u') 
                 ->where('iss.diagnosers = ?1') 
                 ->andWhere('iss.individuals = ?2') 
                 ->setParameters(array(1 => $idDiag, 2 => $id)); 
      

      I retrieve an IndividualsStatus entity:

      object(stdClass)[149] 
        public '__CLASS__' => string 'IndividualsStatus' (length=37) 
        public 'individuals' => 
          object(stdClass)[148] 
            public '__CLASS__' => string 'Individuals' (length=31) 
            public 'reference' => string '451' (length=3) 
            public 'maxAdvertisements' => null 
            public 'role' => int 2 
            public 'id' => int 8 
            public 'users' => string 'Users' (length=25) 
            public 'advertisements' => string 'Array(0)' (length=8) 
            public 'diagnosers' => string 'Array(1)' (length=8) 
            public 'ownedReports' => string 'Array(0)' (length=8) 
            public 'reports' => string 'Array(0)' (length=8) 
            public '_em' => null 
        public 'diagnosers' => 
          object(stdClass)[154] 
            public '__CLASS__' => string 'Proxies 
      \OpengroupeEntitiesDiagnosersProxy' (length=61) 
            public 'id' => string '19' (length=2) 
        public 'statusIndividuals' => int 1 
        public '_em' => null 
      

      Now i want to access to the "Diagnosers" relation of the Individuals:
      \Doctrine\Common\Util\Debug::dump($individualsStatus->getIndividuals()->getDiagnosers());

      In my database, this individuals got 2 diagnosers attached, but only 1 is dumped.
      For getting the 2, i have to select the Diagnosers relation into my Dql request:

         $qb->select(array('i', 'iss', 'u', 'd')) 
                 ->from('IndividualsStatus', 'iss') 
                 ->join('iss.individuals', 'i') 
                 ->join('i.diagnosers', 'd') 
                 ->join('i.users', 'u') 
                 ->where('iss.diagnosers = ?1') 
                 ->andWhere('iss.individuals = ?2') 
                 ->setParameters(array(1 => $idDiag, 2 => $id)); 
      

      Then if i do \Doctrine\Common\Util\Debug::dump($individualsStatus->getIndividuals()->getDiagnosers())
      I have my 2 diagnosers display.

        Activity

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Jonathan Clus
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: