DDC-279: Custom repository method find returns a empty associated class #346

Closed
opened 2026-01-22 12:35:33 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Jan 27, 2010).

Jira issue originally created by user kidh0:

When I try to use a custom repository, as below:

...
        $repository = $em->getRepository('Ciutat\DomainModel\Administrador');
        $administradorResult = $repository->getArrayResult($params['id']);

It returns the Administrador object, but the relations with PessoaFisica comes empty.

The generated SQL is right, with all the joins and is returning the right values, but the object no.

DQL dump:

SELECT a, pf, uf 
FROM Ciutat\DomainModel\Administrador a 
INNER JOIN a.pessoaFisica pf
INNER JOIN pf.ufRg uf WHERE a.id = ?1

SQL dump:

SELECT u0_.ID               AS id0,
       u0_.username         AS username1,
       u0_.ativo            AS ativo2,
       u0_.motivoinativacao AS motivoinativacao3,
       u0_.password         AS password4,
       a1_.nivel            AS nivel5,
       p2_.ID               AS id6,
       p2_.nome             AS nome7,
       p2_.cpf              AS cpf8,
       p2_.rg               AS rg9,
       p2*.emissao_rg       AS emissao*rg10,
       p2*.data_nascimento  AS data*nascimento11,
       p2_.email            AS email12,
       p2_.telefone         AS telefone13,
       u3_.ID               AS id14,
       u3_.nome             AS nome15,
       u3_.sigla            AS sigla16,
       u0_.discr            AS discr17,
       a1*.pessoa_fisica_id AS pessoa_fisica*id18,
       a1*.orgao_id         AS orgao*id19,
       p2*.uf_rg_id         AS uf_rg*id20,
       u3*.pais_id          AS pais*id21
FROM   administrador a1_
       INNER JOIN usuario u0_
         ON a1*.ID = u0*.ID
       INNER JOIN pessoa*fisica p2*
         ON a1*.pessoa_fisica_id = p2*.ID
       INNER JOIN uf u3_
         ON p2*.uf_rg_id = u3*.ID
WHERE  u0_.ID = ? 

Result dump:

object(stdClass)[230]
  public '*_CLASS_*' => string 'Ciutat\DomainModel\Administrador' (length=32)
  public 'nivel' => string 'administrador' (length=13)
  public 'pessoaFisica' => 
    object(stdClass)[266]
      public '*_CLASS_*' => string 'Ciutat\Proxy\CiutatDomainModelPessoaFisicaProxy' (length=47)
      public '_entityPersister' => string 'Doctrine\ORM\Persisters\StandardEntityPersister' (length=47)
      public '_identifier' => string 'Array(1)' (length=8)
      public '*_isInitialized_*' => boolean false
      public 'id' => null
      public 'nome' => null
      public 'rg' => null
      public 'telefone' => null
  public 'orgao' => null
  public 'niveis' => 
    array
      0 => string 'administrador' (length=13)
  public 'id' => int 5
  public 'username' => string 'hboaventura' (length=11)
  public 'ativo' => boolean true
  public 'motivoinativacao' => null
  public 'password' => string '4d0f06ecfcd04e224b8b96248514ab931e0ed259' (length=40)
Originally created by @doctrinebot on GitHub (Jan 27, 2010). Jira issue originally created by user kidh0: When I try to use a custom repository, as below: ``` ... $repository = $em->getRepository('Ciutat\DomainModel\Administrador'); $administradorResult = $repository->getArrayResult($params['id']); ``` It returns the Administrador object, but the relations with PessoaFisica comes empty. The generated SQL is right, with all the joins and is returning the right values, but the object no. DQL dump: ``` SELECT a, pf, uf FROM Ciutat\DomainModel\Administrador a INNER JOIN a.pessoaFisica pf INNER JOIN pf.ufRg uf WHERE a.id = ?1 ``` SQL dump: ``` SELECT u0_.ID AS id0, u0_.username AS username1, u0_.ativo AS ativo2, u0_.motivoinativacao AS motivoinativacao3, u0_.password AS password4, a1_.nivel AS nivel5, p2_.ID AS id6, p2_.nome AS nome7, p2_.cpf AS cpf8, p2_.rg AS rg9, p2*.emissao_rg AS emissao*rg10, p2*.data_nascimento AS data*nascimento11, p2_.email AS email12, p2_.telefone AS telefone13, u3_.ID AS id14, u3_.nome AS nome15, u3_.sigla AS sigla16, u0_.discr AS discr17, a1*.pessoa_fisica_id AS pessoa_fisica*id18, a1*.orgao_id AS orgao*id19, p2*.uf_rg_id AS uf_rg*id20, u3*.pais_id AS pais*id21 FROM administrador a1_ INNER JOIN usuario u0_ ON a1*.ID = u0*.ID INNER JOIN pessoa*fisica p2* ON a1*.pessoa_fisica_id = p2*.ID INNER JOIN uf u3_ ON p2*.uf_rg_id = u3*.ID WHERE u0_.ID = ? ``` Result dump: ``` object(stdClass)[230] public '*_CLASS_*' => string 'Ciutat\DomainModel\Administrador' (length=32) public 'nivel' => string 'administrador' (length=13) public 'pessoaFisica' => object(stdClass)[266] public '*_CLASS_*' => string 'Ciutat\Proxy\CiutatDomainModelPessoaFisicaProxy' (length=47) public '_entityPersister' => string 'Doctrine\ORM\Persisters\StandardEntityPersister' (length=47) public '_identifier' => string 'Array(1)' (length=8) public '*_isInitialized_*' => boolean false public 'id' => null public 'nome' => null public 'rg' => null public 'telefone' => null public 'orgao' => null public 'niveis' => array 0 => string 'administrador' (length=13) public 'id' => int 5 public 'username' => string 'hboaventura' (length=11) public 'ativo' => boolean true public 'motivoinativacao' => null public 'password' => string '4d0f06ecfcd04e224b8b96248514ab931e0ed259' (length=40) ```
admin added the Bug label 2026-01-22 12:35:33 +01:00
admin closed this issue 2026-01-22 12:35:33 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jan 27, 2010):

Comment created by @beberlei:

I committed a testcase that shows it works:

benny@benny-pc:~/code/php/wsnetbeans/Doctrine/trunk/tests$ phpunit --group [DDC-279](http://www.doctrine-project.org/jira/browse/DDC-279) Doctrine/Tests/AllTests.php
@doctrinebot commented on GitHub (Jan 27, 2010): Comment created by @beberlei: I committed a testcase that shows it works: ``` benny@benny-pc:~/code/php/wsnetbeans/Doctrine/trunk/tests$ phpunit --group [DDC-279](http://www.doctrine-project.org/jira/browse/DDC-279) Doctrine/Tests/AllTests.php ```
Author
Owner

@doctrinebot commented on GitHub (Jan 28, 2010):

Comment created by kidh0:

I customized your test do reflect my exactly situation, and it really works.

But what I commit a mistake, isn't the getArrayResult() method that I have a problem, is the getSingleResult() method

I attached the adapted test case

@doctrinebot commented on GitHub (Jan 28, 2010): Comment created by kidh0: I customized your test do reflect my exactly situation, and it really works. But what I commit a mistake, isn't the getArrayResult() method that I have a problem, is the getSingleResult() method I attached the adapted test case
Author
Owner

@doctrinebot commented on GitHub (Jan 28, 2010):

Comment created by @beberlei:

Updated smaller test-case that still shows the failure.

@doctrinebot commented on GitHub (Jan 28, 2010): Comment created by @beberlei: Updated smaller test-case that still shows the failure.
Author
Owner

@doctrinebot commented on GitHub (Jan 29, 2010):

Comment created by romanb:

Should be fixed now.

@doctrinebot commented on GitHub (Jan 29, 2010): Comment created by romanb: Should be fixed now.
Author
Owner

@doctrinebot commented on GitHub (Jan 29, 2010):

Issue was closed with resolution "Fixed"

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

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

Imported 3 attachments from Jira into https://gist.github.com/a5a82df42d5abbea1e05

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 3 attachments from Jira into https://gist.github.com/a5a82df42d5abbea1e05 - [10319_Ciutat.DomainModel.Usuario.dcm.yml](https://gist.github.com/a5a82df42d5abbea1e05#file-10319_Ciutat-DomainModel-Usuario-dcm-yml) - [10326_DDC279Test.php](https://gist.github.com/a5a82df42d5abbea1e05#file-10326_DDC279Test-php) - [10327_DDC279Test.php](https://gist.github.com/a5a82df42d5abbea1e05#file-10327_DDC279Test-php)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#346