Understanding Partial object hydration #6822

Closed
opened 2026-01-22 15:39:30 +01:00 by admin · 1 comment
Owner

Originally created by @flaushi on GitHub (Sep 8, 2021).

Bug Report

Q A
BC Break no
Version 2.8.4

Summary

I query all objects of one type partially to have them in the UoW. Although I do not mention some self-referencing ManyToOne associations in this query, they still are hydrated and point to their partial siblings. That would be fine for me. However some (speaking of 200.000 out of 900.000) get hydrated fully (with extra queries) and I have to find out why.

Current behavior

20% of the entities in the UoW are hydrated fully

How to reproduce

My class:

class DataCategory {
    /**
     * @ORM\Id
     * @ORM\Column(type="uuid", unique=true)
     */
    protected $id;
    
    /**
     * @ORM\Column(type="string", length=1023, options={"default" : ""})
     */
    public $description = "";

    /**
     * @var DataCategory
     * @ORM\ManyToOne(targetEntity="DataCategory")
     * @ORM\JoinColumn(referencedColumnName="id")
     */
    public $dc1;
}

My query that should just fill the UoW: (not it does not query the association, but still these associations are present in the objects finally)

$this->em->createQuery('SELECT partial d.{id} FROM App\Entity\DataCategory d')->getResult();

This test should return the number zero

$this->output(count(
                array_filter($this->em->getUnitOfWork()->getIdentityMap()[DataCategory::class],
                    fn($dc) => $dc->description === '')));

but there are over 200.000 out of 900.000 total array elements which are fully hydrated. Could it be that the association gets hydrated fully if the loop that hydrates all queries has not reached the linked object? Can I somehow circumvent that?

I simplified one detail here, i.e. DataCategory is an abstract class in reality, and I query all child classes.

You would help me greatly if you could point me the the code that does the partial hydration and especially the associations.

Expected behavior

All object shoudl be in the UoW partially, i.e. description === ''

Originally created by @flaushi on GitHub (Sep 8, 2021). ### Bug Report | Q | A |------------ | ------ | BC Break |no | Version | 2.8.4 #### Summary I query all objects of one type partially to have them in the UoW. Although I do not mention some self-referencing ManyToOne associations in this query, they still are hydrated and point to their partial siblings. That would be fine for me. However some (speaking of 200.000 out of 900.000) get hydrated fully (with extra queries) and I have to find out why. #### Current behavior 20% of the entities in the UoW are hydrated fully #### How to reproduce My class: ``` class DataCategory { /** * @ORM\Id * @ORM\Column(type="uuid", unique=true) */ protected $id; /** * @ORM\Column(type="string", length=1023, options={"default" : ""}) */ public $description = ""; /** * @var DataCategory * @ORM\ManyToOne(targetEntity="DataCategory") * @ORM\JoinColumn(referencedColumnName="id") */ public $dc1; } ``` My query that should just fill the UoW: (not it does not query the association, but still these associations are present in the objects finally) ``` $this->em->createQuery('SELECT partial d.{id} FROM App\Entity\DataCategory d')->getResult(); ``` This test should return the number zero ``` $this->output(count( array_filter($this->em->getUnitOfWork()->getIdentityMap()[DataCategory::class], fn($dc) => $dc->description === ''))); ``` but there are over 200.000 out of 900.000 total array elements which are fully hydrated. Could it be that the association gets hydrated fully if the loop that hydrates all queries has not reached the linked object? Can I somehow circumvent that? I simplified one detail here, i.e. `DataCategory` is an abstract class in reality, and I query all child classes. You would help me greatly if you could point me the the code that does the partial hydration and especially the associations. #### Expected behavior All object shoudl be in the UoW partially, i.e. `description === ''`
admin closed this issue 2026-01-22 15:39:30 +01:00
Author
Owner

@beberlei commented on GitHub (Sep 8, 2021):

Partial objects are deprecated and will be removed in 3.0

The partiallity mostly refers to simple fields not to associations.

@beberlei commented on GitHub (Sep 8, 2021): Partial objects are deprecated and will be removed in 3.0 The partiallity mostly refers to simple fields not to associations.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6822