Embedded Relations #6195

Closed
opened 2026-01-22 15:28:38 +01:00 by admin · 4 comments
Owner

Originally created by @elvispdosreis on GitHub (Mar 3, 2019).

Originally assigned to: @Ocramius on GitHub.

Q A
Version 2.6

Support Question

Is it possible to accomplish this type relationship, within an embedded class having a relationship with another table?

<?php

/** @Entity */
class User
{
    /** @Embedded(class = "Address") */
    private $address;
}

/** @Embeddable */
class Address
{
    /** @Column(type = "string") */
    private $street;

    /** @Column(type = "string") */
    private $postalCode;

    /** @Column(type = "string") */
    private $city;

    /**
     * @ManyToOne(targetEntity="Country")
     */
    private $country;
}

/** @Entity */
class Country
{
     /** @Column(type = "string") */
    private $code;

    /** @Column(type = "string") */
    private $name;
}
Originally created by @elvispdosreis on GitHub (Mar 3, 2019). Originally assigned to: @Ocramius on GitHub. <!-- Fill in the relevant information below to help triage your issue. --> | Q | A |------------ | ----- | Version | 2.6 <!-- Before asking question here, please try asking on Gitter or Slack first. Find out more about Doctrine support channels here: https://www.doctrine-project.org/community/ Keep in mind that GitHub is primarily an issue tracker. --> ### Support Question Is it possible to accomplish this type relationship, within an embedded class having a relationship with another table? ``` <?php /** @Entity */ class User { /** @Embedded(class = "Address") */ private $address; } /** @Embeddable */ class Address { /** @Column(type = "string") */ private $street; /** @Column(type = "string") */ private $postalCode; /** @Column(type = "string") */ private $city; /** * @ManyToOne(targetEntity="Country") */ private $country; } /** @Entity */ class Country { /** @Column(type = "string") */ private $code; /** @Column(type = "string") */ private $name; } ```
admin added the Won't FixQuestion labels 2026-01-22 15:28:38 +01:00
admin closed this issue 2026-01-22 15:28:38 +01:00
Author
Owner

@lashus commented on GitHub (Mar 11, 2019):

@elvispdosreis As far as I can tell from the documentation it is not. See: https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/tutorials/embeddables.html and the yellow note :)

@lashus commented on GitHub (Mar 11, 2019): @elvispdosreis As far as I can tell from the documentation it is not. See: https://www.doctrine-project.org/projects/doctrine-orm/en/2.6/tutorials/embeddables.html and the yellow note :)
Author
Owner

@Ocramius commented on GitHub (Mar 11, 2019):

Closing as per @lashus' review.

@Ocramius commented on GitHub (Mar 11, 2019): Closing as per @lashus' review.
Author
Owner

@Spomsoree commented on GitHub (Feb 13, 2020):

Could this case somehow throw an error or something?
I just tried to group all pictures of an entity inside an embeddable, and wondered why no database field were created.

Doctrine accepted my configuration without a doubt, but did no create mentioned fields.

@Spomsoree commented on GitHub (Feb 13, 2020): Could this case somehow throw an error or something? I just tried to group all pictures of an entity inside an embeddable, and wondered why no database field were created. Doctrine accepted my configuration without a doubt, but did no create mentioned fields.
Author
Owner

@BonBonSlick commented on GitHub (Mar 10, 2021):

Would appriciate error or notification. We had a case

abstract class AbstractCredentialsVO extends AbstractVO {
    private ?string                                $email;
    private ?User                                  $user;

@BonBonSlick commented on GitHub (Mar 10, 2021): Would appriciate error or notification. We had a case ``` abstract class AbstractCredentialsVO extends AbstractVO { private ?string $email; private ?User $user; ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6195