DDC-419: Problem when I make a INNER JOIN between 2 classes #523

Closed
opened 2026-01-22 12:41:23 +01:00 by admin · 15 comments
Owner

Originally created by @doctrinebot on GitHub (Mar 12, 2010).

Jira issue originally created by user hgirardi:

I hae some problems when I make a inner join between 2 classes, one of these classes makes join to others 2 classes in the same time and when I try to make a inner to this class, it's not coming like a object, but object Id...

I don't know why its happening..

I make a test case..there're all the classes and yml that show my problem..it's on ItemPregaoTest.php.. just need to run phpunit in this file..

Originally created by @doctrinebot on GitHub (Mar 12, 2010). Jira issue originally created by user hgirardi: I hae some problems when I make a inner join between 2 classes, one of these classes makes join to others 2 classes in the same time and when I try to make a inner to this class, it's not coming like a object, but object Id... I don't know why its happening.. I make a test case..there're all the classes and yml that show my problem..it's on ItemPregaoTest.php.. just need to run phpunit in this file..
admin added the Bug label 2026-01-22 12:41:23 +01:00
admin closed this issue 2026-01-22 12:41:23 +01:00
Author
Owner

@doctrinebot commented on GitHub (Mar 12, 2010):

@doctrinebot commented on GitHub (Mar 12, 2010): - depends on [DDC-522: Join columns can not be named the same as the association fields.](http://www.doctrine-project.org/jira/browse/DDC-522)
Author
Owner

@doctrinebot commented on GitHub (Mar 14, 2010):

Comment created by @beberlei:

This is what returns for me:

object(stdClass)[82]
  public '*_CLASS_*' => string 'ItemPregao' (length=10)
  public 'id' => int 1
  public 'item' => string '1' (length=1)

The expected result I guess. What happens for you?

@doctrinebot commented on GitHub (Mar 14, 2010): Comment created by @beberlei: This is what returns for me: ``` object(stdClass)[82] public '*_CLASS_*' => string 'ItemPregao' (length=10) public 'id' => int 1 public 'item' => string '1' (length=1) ``` The expected result I guess. What happens for you?
Author
Owner

@doctrinebot commented on GitHub (Mar 14, 2010):

Comment created by hgirardi:

Ok...this is what happen for me...
but I think the expected result would be

object(stdClass)[82]
  public '*_CLASS_*' => string 'ItemPregao' (length=10)
  public 'id' => int 1
  public 'item' => string 'Item' (length=4)

because 'public item' makes refereces to Item class, so I think it should give me a Item class, not its Id...

@doctrinebot commented on GitHub (Mar 14, 2010): Comment created by hgirardi: Ok...this is what happen for me... but I think the expected result would be ``` object(stdClass)[82] public '*_CLASS_*' => string 'ItemPregao' (length=10) public 'id' => int 1 public 'item' => string 'Item' (length=4) ``` because 'public item' makes refereces to Item class, so I think it should give me a Item class, not its Id...
Author
Owner

@doctrinebot commented on GitHub (Mar 16, 2010):

Comment created by hgirardi:

When I try to make a inner join between Item and ItemPregao, happens what I've said before, but if I make a inner join between Item and its refereces tables, it's working fine

$qb = $this->em->createQueryBuilder();
        $qb->select('i, cc, ca, cl')
           ->from('Item', 'i')
           ->innerJoin('i.classificacaoCatalogo', 'cc')
           ->innerJoin('cc.catalogo', 'ca')
           ->innerJoin('cc.classificacao', 'cl')
        ;

object(stdClass)[141]
  public '*_CLASS_*' => string 'Item' (length=4)
  public 'id' => int 1
  public 'descricao' => string 'ITEM 1' (length=6)
  public 'classificacaoCatalogo' => 
    object(stdClass)[99]
      public '*_CLASS_*' => string 'ClassificacaoCatalogo' (length=21)
      public 'id' => int 1
      public 'classificacao' => string 'Classificacao' (length=13)
      public 'catalogo' => string 'Catalogo' (length=8)

It brings a class on 'classificacaoCatalogo' and inside classificacaoCatalogo you can see that 'classificacao' and 'catalogo' are objects too..so it worked! But If I make this:

$qb = $this->em->createQueryBuilder();
        $qb->select('ip, i')
           ->from('ItemPregao', 'ip')
           ->innerJoin('ip.item', 'i');

do not work like before..

object(stdClass)[152]
  public '*_CLASS_*' => string 'ItemPregao' (length=10)
  public 'id' => int 1
  public 'item' => int 1

'item' should be a object, not a integer..

@doctrinebot commented on GitHub (Mar 16, 2010): Comment created by hgirardi: When I try to make a inner join between Item and ItemPregao, happens what I've said before, but if I make a inner join between Item and its refereces tables, it's working fine ``` $qb = $this->em->createQueryBuilder(); $qb->select('i, cc, ca, cl') ->from('Item', 'i') ->innerJoin('i.classificacaoCatalogo', 'cc') ->innerJoin('cc.catalogo', 'ca') ->innerJoin('cc.classificacao', 'cl') ; object(stdClass)[141] public '*_CLASS_*' => string 'Item' (length=4) public 'id' => int 1 public 'descricao' => string 'ITEM 1' (length=6) public 'classificacaoCatalogo' => object(stdClass)[99] public '*_CLASS_*' => string 'ClassificacaoCatalogo' (length=21) public 'id' => int 1 public 'classificacao' => string 'Classificacao' (length=13) public 'catalogo' => string 'Catalogo' (length=8) ``` It brings a class on 'classificacaoCatalogo' and inside classificacaoCatalogo you can see that 'classificacao' and 'catalogo' are objects too..so it worked! But If I make this: ``` $qb = $this->em->createQueryBuilder(); $qb->select('ip, i') ->from('ItemPregao', 'ip') ->innerJoin('ip.item', 'i'); ``` do not work like before.. ``` object(stdClass)[152] public '*_CLASS_*' => string 'ItemPregao' (length=10) public 'id' => int 1 public 'item' => int 1 ``` 'item' should be a object, not a integer..
Author
Owner

@doctrinebot commented on GitHub (Mar 16, 2010):

Comment created by @beberlei:

Ah now I see it. Yes, this seems to be a problem.

@doctrinebot commented on GitHub (Mar 16, 2010): Comment created by @beberlei: Ah now I see it. Yes, this seems to be a problem.
Author
Owner

@doctrinebot commented on GitHub (Mar 18, 2010):

Comment created by @beberlei:

I have taken some time now trying to re-produce it, there is definately a bug i have identified, however i havent found the reason yet.

@doctrinebot commented on GitHub (Mar 18, 2010): Comment created by @beberlei: I have taken some time now trying to re-produce it, there is definately a bug i have identified, however i havent found the reason yet.
Author
Owner

@doctrinebot commented on GitHub (Mar 18, 2010):

Comment created by hgirardi:

ok man!
I've try to find the reason too but I havent found yet too...
I dont know if there's something about the item are conected to a table that there're 2 table...
i dont know :S

@doctrinebot commented on GitHub (Mar 18, 2010): Comment created by hgirardi: ok man! I've try to find the reason too but I havent found yet too... I dont know if there's something about the item are conected to a table that there're 2 table... i dont know :S
Author
Owner

@doctrinebot commented on GitHub (Mar 20, 2010):

Comment created by @beberlei:

I found the issue. A quick fix is to rename the join column to "item_id" instead of "item". This is causing the bug, we will look how to fix it.

@Roman:

This is particularly nasty, in UnitOfWork::createEntity the join column is set to the field name in $data, which makes the following code write the primitive FK value to the entity:

            if ($this->_useCExtension) {
                doctrine*populate*data($entity, $data);
            } else {
                foreach ($data as $field => $value) {
                    if (isset($class->reflFields[$field])) {
                        $class->reflFields[$field]->setValue($entity, $value);
                    }
                }
            }

This then leads in the ObjectHydrator to:

                    // PATH B: Single-valued association
                    $reflFieldValue = $reflField->getValue($parentObject);
                    if ( ! $reflFieldValue || isset($this->*hints[Query::HINT*REFRESH])) {

not evaluating to null, but to the primitive value. the If condition does not match here and the relation is never set.

A simple solution would be to replace !$reflFieldValue with !is_object().

@doctrinebot commented on GitHub (Mar 20, 2010): Comment created by @beberlei: I found the issue. A quick fix is to rename the join column to "item_id" instead of "item". This is causing the bug, we will look how to fix it. @Roman: This is particularly nasty, in UnitOfWork::createEntity the join column is set to the field name in $data, which makes the following code write the primitive FK value to the entity: ``` if ($this->_useCExtension) { doctrine*populate*data($entity, $data); } else { foreach ($data as $field => $value) { if (isset($class->reflFields[$field])) { $class->reflFields[$field]->setValue($entity, $value); } } } ``` This then leads in the ObjectHydrator to: ``` // PATH B: Single-valued association $reflFieldValue = $reflField->getValue($parentObject); if ( ! $reflFieldValue || isset($this->*hints[Query::HINT*REFRESH])) { ``` not evaluating to null, but to the primitive value. the If condition does not match here and the relation is never set. A simple solution would be to replace !$reflFieldValue with !is_object().
Author
Owner

@doctrinebot commented on GitHub (Mar 20, 2010):

Comment created by @beberlei:

Attached a reproduce test-case.

@doctrinebot commented on GitHub (Mar 20, 2010): Comment created by @beberlei: Attached a reproduce test-case.
Author
Owner

@doctrinebot commented on GitHub (Mar 20, 2010):

Comment created by romanb:

I see. As their is an easy workaround, this is not a blocker, however.

@doctrinebot commented on GitHub (Mar 20, 2010): Comment created by romanb: I see. As their is an easy workaround, this is not a blocker, however.
Author
Owner

@doctrinebot commented on GitHub (Apr 15, 2010):

Comment created by romanb:

DDC-522 needs to be fixed, then this issue is solved, too (its the same after all, the other issue is just more specific).

@doctrinebot commented on GitHub (Apr 15, 2010): Comment created by romanb: [DDC-522](http://www.doctrine-project.org/jira/browse/DDC-522) needs to be fixed, then this issue is solved, too (its the same after all, the other issue is just more specific).
Author
Owner

@doctrinebot commented on GitHub (Apr 15, 2010):

Comment created by romanb:

Scheduled for beta2

@doctrinebot commented on GitHub (Apr 15, 2010): Comment created by romanb: Scheduled for beta2
Author
Owner

@doctrinebot commented on GitHub (Aug 8, 2010):

Comment created by romanb:

Should be fixed now in master.

@doctrinebot commented on GitHub (Aug 8, 2010): Comment created by romanb: Should be fixed now in master.
Author
Owner

@doctrinebot commented on GitHub (Aug 8, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Aug 8, 2010): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/486fc12da318be5d18ba

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/486fc12da318be5d18ba - [10509_DDC419Test.php](https://gist.github.com/486fc12da318be5d18ba#file-10509_DDC419Test-php)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#523