Initialize proxies with all their collections already being PersistentCollection #5710

Open
opened 2026-01-22 15:15:19 +01:00 by admin · 0 comments
Owner

Originally created by @Ocramius on GitHub (Sep 23, 2017).

Originally assigned to: @Ocramius on GitHub.

Starting with #6719, proxies can be partially loaded by just deciding which fields are to be lazy-loaded and which are not: this allows us to initialize them with empty PersistentCollection instances upfront.

Take this example:

class Comment
{
    public $id;
}

class BlogPost
{
    public $id;
    public $comments = [];
}

$blogPost = $em->getReference(BlogPost::class, ['id' => 123]);

var_dump(count($blogPost->comments));

The logic above triggers two SELECT queries in ORM 2.x. In ORM 3.x, we could make it perform just the SELECT query that initializes the BlogPost#$comments collection if the property is always replaced with a Doctrine\ORM\PersistentCollection

Originally created by @Ocramius on GitHub (Sep 23, 2017). Originally assigned to: @Ocramius on GitHub. Starting with #6719, proxies can be partially loaded by just deciding which fields are to be lazy-loaded and which are not: this allows us to initialize them with empty `PersistentCollection` instances upfront. Take this example: ```php class Comment { public $id; } class BlogPost { public $id; public $comments = []; } $blogPost = $em->getReference(BlogPost::class, ['id' => 123]); var_dump(count($blogPost->comments)); ``` The logic above triggers two `SELECT` queries in ORM 2.x. In ORM 3.x, we could make it perform just the `SELECT` query that initializes the `BlogPost#$comments` collection if the property is always replaced with a `Doctrine\ORM\PersistentCollection`
admin added the Improvement label 2026-01-22 15:15:19 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5710