Skip to content

Loading…

DDC-3136: DQL JOIN association return null #3914

Open
doctrinebot opened this Issue · 0 comments

2 participants

@doctrinebot

Jira issue originally created by user raphpar:

Hello,
I observe a strange behavior of a query result done by DQL (only tested DQL in fact). In the last entry of my result, the joined entity are returned to null

My tables are:

/****
 * @ORM\Table(name="entity1")
 * @ORM\Entity()
****/
class Entity1
{   
     /****
     * @ORM\Column(name="entity1_id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $entity1_Id; 

    /****
    * @ORM\Column(name="entity1_text", type="string")
    */
    protected $entity1_Text;
}
/****
 * @ORM\Table(name="entity2")
 * @ORM\Entity()
****/
class Entity2
{   
        /****
    * @ORM\OneToOne(targetEntity="Entity1")
    * @ORM\JoinColumn(name="entity1*id", referencedColumnName="entity1*id")
    * @ORM\Id
    */
    protected $entity1_id; 

    /****
    * @ORM\ManyToOne(targetEntity="Entity3")
    * @ORM\JoinColumn(name="entity3*id", referencedColumnName="entity3*id")
    */
    protected $entity3; 
}
/****
 * @ORM\Table(name="entity3")
 * @ORM\Entity()
****/
class Entity3
{   
     /****
     * @ORM\Column(name="entity3_id", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $entity3_Id; 

    /****
    * @ORM\Column(name="entity3_text", type="string")
    */
    protected $entity3_Text;
}

So when I do a simple request like this:

SELECT ent2, ent3 FROM f4cIndexBundle:Entity2 ent2 JOIN ent2.entity3 ent3

The result is looks like this

array (size=2)
  0 => 
    object(f4c\IndexBundle\Entity\Entity2)[550]
      protected 'entity1_id' => 
        object(Proxies\*_CG_*\f4c\IndexBundle\Entity\Entity1)[502]
          ...
      protected 'entity3' => 
        object(f4c\IndexBundle\Entity\Entity3)[497]
          protected 'entity3_Id' => int 2
          protected 'entity3_Text' => string 'TEXT OF ENTITY 3 - SPECIFIC 2' (length=29)
  1 => 
    object(f4c\IndexBundle\Entity\Entity2)[498]
      protected 'entity1_id' => 
        object(Proxies\*_CG_*\f4c\IndexBundle\Entity\Entity1)[499]
          ...
     protected 'entity3' => null

The entity3 of the last result is never joined and set to null (it's not possible because of the JOIN no ?)
I spent to days on this and I observed that when I add a property in my entity 2 like this

/****
 * @ORM\Table(name="entity2")
 * @ORM\Entity()
****/
class Entity2
{   
    ...
    /****
    * @ORM\Column(name="entity2_text", type="string")
    */
    protected $entity2_Text;
}

The result is ok

array (size=2)
  0 => 
    object(f4c\IndexBundle\Entity\Entity2)[550]
      protected 'entity1_id' => 
        object(Proxies\*_CG_*\f4c\IndexBundle\Entity\Entity1)[498]
         ...
      protected 'entity2_Text' => string 'TEXT2' (length=5)
      protected 'entity3' => 
        object(f4c\IndexBundle\Entity\Entity3)[499]
          protected 'entity3_Id' => int 1
          protected 'entity3_Text' => string 'TEXT OF ENTITY 3 - SPECIFIC 1' (length=29)
  1 => 
    object(f4c\IndexBundle\Entity\Entity2)[494]
      protected 'entity1_id' => 
        object(Proxies\*_CG_*\f4c\IndexBundle\Entity\Entity1)[495]
          ...
      protected 'entity2_Text' => string 'TEXT1' (length=5)
      protected 'entity3' => 
        object(f4c\IndexBundle\Entity\Entity3)[496]
          protected 'entity3_Id' => int 2
          protected 'entity3_Text' => string 'TEXT OF ENTITY 3 - SPECIFIC 2' (length=29)

Is it normal ? Is this a kwon issue ?

Thanks for your help

Raphael P.

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.