[PR #265] [WIP] Mapping support for Embeddables (VOs). #7941

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

Original Pull Request: https://github.com/doctrine/orm/pull/265

State: closed
Merged: No


This patch is going to address: http://www.doctrine-project.org/jira/browse/DDC-93

Embeddable classes are a good way for organizing your domain model. Specially larger systems, which contains similar domain objects with similar properties.
This patch proposes a cleaner way to structure these duplicating attributes (and logic) into an @Embeddable object. Abstract the common information into an @Embeddedable object and use it as @Embedded.

/**
 * @Embeddable
 */
class Location
{
    /** @Column(type="decimal", scale=8, precision=12, nullable=true) */
    protected $latitude;

    /** @Column(type="decimal", scale=8, precision=12, nullable=true) */
    protected $longitude;
}

/**
 * @Entity 
 */
class User
{
    /** @Id @GeneratedValue @Column(type="integer") */
    protected $id;

    // ...

    /** @Embedded(class="Location") */
    protected $location;
}

Querying:

$query = $entityManager->createQuery('SELECT u FROM User u WHERE u.location.latitude = ?1');
**Original Pull Request:** https://github.com/doctrine/orm/pull/265 **State:** closed **Merged:** No --- This patch is going to address: http://www.doctrine-project.org/jira/browse/DDC-93 Embeddable classes are a good way for organizing your domain model. Specially larger systems, which contains similar domain objects with similar properties. This patch proposes a cleaner way to structure these duplicating attributes (and logic) into an @Embeddable object. Abstract the common information into an @Embeddedable object and use it as @Embedded. ``` php /** * @Embeddable */ class Location { /** @Column(type="decimal", scale=8, precision=12, nullable=true) */ protected $latitude; /** @Column(type="decimal", scale=8, precision=12, nullable=true) */ protected $longitude; } /** * @Entity */ class User { /** @Id @GeneratedValue @Column(type="integer") */ protected $id; // ... /** @Embedded(class="Location") */ protected $location; } ``` Querying: ``` php $query = $entityManager->createQuery('SELECT u FROM User u WHERE u.location.latitude = ?1'); ```
admin added the pull-request label 2026-01-22 15:57:39 +01:00
admin closed this issue 2026-01-22 15:57:39 +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#7941