[DDC-1176] Error on proxy loading with foreign Key Created: 27/May/11  Updated: 11/Jun/11  Resolved: 11/Jun/11

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.1
Fix Version/s: 2.1
Security Level: All

Type: Bug Priority: Blocker
Reporter: Jonathan Clus Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 0
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.



 Comments   
Comment by Jonathan Clus [ 27/May/11 ]

I test something more simple with the same entiies:

$diagnosers = $em->getRepository('Diagnosers')->find(19);
$listDiag = $diagnosers->getIndividuals();

In my database, the Diagnoser(19) got 20 individualsStatus(remember the relation called "Individuals" in "Diagnosers" return "IndividualsStatus" entities)
So this function return only 1 individualStatus(minor id in bdd).

I am completly blocked in my developpement. Did my entity annotation for the relation is bad ?

Comment by Benjamin Eberlei [ 05/Jun/11 ]

Formatting

Comment by Benjamin Eberlei [ 05/Jun/11 ]

This issue is related to foreign key identifiers, not using them will solve the problem. Your annotations are good.

However I fixed an issue of this kind some weeks ago. Are you using the Download of 2.1 Beta? Can you try to update to the latest version on Git?

Comment by Benjamin Eberlei [ 05/Jun/11 ]

Yes just seeing i fixed the bug AFTER releasing BEta 1. Please upgrade and verify!

Comment by Benjamin Eberlei [ 11/Jun/11 ]

Resolved

Generated at Sat Oct 25 14:37:29 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.