DDC-371: Some associations not included in a HINT_REFRESH joined query are selected afterwards #463

Closed
opened 2026-01-22 12:39:06 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Feb 25, 2010).

Jira issue originally created by user reinier.kip:

See http://groups.google.com/group/doctrine-user/browse_thread/thread/c711e742b860da9a/45ce810779b838d3

Some associations not included in a HINT_REFRESH joined query are selected afterwards, but their collections are not initialised. When selecting a child and its parent, the parents children are also selected afterwards (thus resulting in two queries), yet the associated collection is not initialised. The first issue here is that the children are selected even though I don't ask for them. If this, however, is expected behaviour in HINT_REFRESH joined queries, another issue is that the collection is not initialised. This can best be demonstrated using an example:

        /*** @Entity **/
        class Child {
                /*** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") **/
                private $id;
                /*** @Column(type="string") **/
                public $data;
                /*** @ManyToOne(targetEntity="Parentt") @JoinColumn(name="parentId", referencedColumnName="id") **/
                public $parent;
        }

        /*** @Entity **/
        class Parentt {
                /*** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") **/
                private $id;
                /*** @Column(type="string") **/
                public $data;
                /*** @OneToMany(targetEntity="Child", mappedBy="parent") **/
                public $children;
        }

        $children = $em->createQueryBuilder()
                ->select('c', 'p')
                ->from('Child', 'c')
                ->leftJoin('c.parent', 'p')
                ->where('c.id = 1')
                ->andWhere('p.id = 1')
                ->getQuery()
                ->setHint(Doctrine\ORM\Query::HINT_REFRESH, true)
                ->getResult(); 

This results in a child with a parent, a parent with an uninitialised children collection and these queries:

SELECT c0*.id AS id0, c0_.data AS data1, p1_.id AS id2, p1_.data AS data3, c0_.parentId AS parentId4 FROM Child c0_ LEFT JOIN Parentt p1_ ON c0_.parentId = p1_.id WHERE (c0_.id = 0) AND (p1*.id = 0)
SELECT Child.id, Child.data, parentId FROM Child WHERE parentId = ? array(1) { [0]=>  int(0) } 

Expected behaviour:

  1. The parent's children are not selected at all; (preferred)
  2. or, the parent's children are selected AND the collection is initialised.
Originally created by @doctrinebot on GitHub (Feb 25, 2010). Jira issue originally created by user reinier.kip: See http://groups.google.com/group/doctrine-user/browse_thread/thread/c711e742b860da9a/45ce810779b838d3 Some associations not included in a HINT_REFRESH joined query are selected afterwards, but their collections are not initialised. When selecting a child and its parent, the parents children are also selected afterwards (thus resulting in two queries), yet the associated collection is not initialised. The first issue here is that the children are selected even though I don't ask for them. If this, however, is expected behaviour in HINT_REFRESH joined queries, another issue is that the collection is not initialised. This can best be demonstrated using an example: ``` /*** @Entity **/ class Child { /*** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") **/ private $id; /*** @Column(type="string") **/ public $data; /*** @ManyToOne(targetEntity="Parentt") @JoinColumn(name="parentId", referencedColumnName="id") **/ public $parent; } /*** @Entity **/ class Parentt { /*** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") **/ private $id; /*** @Column(type="string") **/ public $data; /*** @OneToMany(targetEntity="Child", mappedBy="parent") **/ public $children; } $children = $em->createQueryBuilder() ->select('c', 'p') ->from('Child', 'c') ->leftJoin('c.parent', 'p') ->where('c.id = 1') ->andWhere('p.id = 1') ->getQuery() ->setHint(Doctrine\ORM\Query::HINT_REFRESH, true) ->getResult(); ``` This results in a child with a parent, a parent with an uninitialised children collection and these queries: ``` SELECT c0*.id AS id0, c0_.data AS data1, p1_.id AS id2, p1_.data AS data3, c0_.parentId AS parentId4 FROM Child c0_ LEFT JOIN Parentt p1_ ON c0_.parentId = p1_.id WHERE (c0_.id = 0) AND (p1*.id = 0) SELECT Child.id, Child.data, parentId FROM Child WHERE parentId = ? array(1) { [0]=> int(0) } ``` Expected behaviour: 1. The parent's children are not selected at all; (preferred) 2. or, the parent's children are selected AND the collection is initialised.
admin added the Bug label 2026-01-22 12:39:06 +01:00
admin closed this issue 2026-01-22 12:39:06 +01:00
Author
Owner

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

Comment created by romanb:

Should be fixed now.

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

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

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Feb 27, 2010): Issue was closed with resolution "Fixed"
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#463