Lazy Fields automatically create Partial Objects omitting columns from initial load. #7570

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

Originally created by @beberlei on GitHub (Nov 5, 2025).

With native lazy loading support and partial objects as lazy objects, another feature that we could "easily" implement is marking columns as lazy, which would automatically make an entity a partial object.

<?php

#[Entity]
class Post
{
    #[Id, GeneratedValue, Column(type: Types::INTEGER)]
    public int $id;
    #[Column]
    public string $title;
    #[Column, Lazy]
    public string $body;
}

$post = $entityManager->find(Post::class, 1);
echo $post->title; // direct access
echo $post->body; // triggers lazy loading SELECT body FROM post WHERE id = 1

This also requires a way to specify that an object should be "FULLY" loaded from the beginning, i don't. have a complete idea on how to do that, multiple options:

  1. DQL keyword SELECT FULL p FROM Post p
  2. Allow passing $hints to finder methods, $entityManager->find(1, hints: [Query::HINT_FORCE_FULL_LOAD => true]) or ssomething similar.

Related:

Originally created by @beberlei on GitHub (Nov 5, 2025). With native lazy loading support and partial objects as lazy objects, another feature that we could "easily" implement is marking columns as lazy, which would automatically make an entity a partial object. ```php <?php #[Entity] class Post { #[Id, GeneratedValue, Column(type: Types::INTEGER)] public int $id; #[Column] public string $title; #[Column, Lazy] public string $body; } $post = $entityManager->find(Post::class, 1); echo $post->title; // direct access echo $post->body; // triggers lazy loading SELECT body FROM post WHERE id = 1 ``` This also requires a way to specify that an object should be "FULLY" loaded from the beginning, i don't. have a complete idea on how to do that, multiple options: 1. DQL keyword `SELECT FULL p FROM Post p` 2. Allow passing `$hints` to finder methods, `$entityManager->find(1, hints: [Query::HINT_FORCE_FULL_LOAD => true])` or ssomething similar. Related: * #12209 * https://github.com/doctrine/orm/issues/5659
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7570