8000 [DoctrineBridge] DoctrineLoader can't access nested embedded object properties · Issue #31911 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DoctrineBridge] DoctrineLoader can't access nested embedded object properties #31911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
martiis opened this issue Jun 6, 2019 · 2 comments
Closed

Comments

@martiis
Copy link
Contributor
martiis commented Jun 6, 2019

Symfony version(s) affected: 4.3.x

Description
#31775 tackled the issue and #31811 solved it when embedded object does not have an embedded object in it self. The problem still remains when f.e. embedded object is in embedded object in entity.

How to reproduce
Entities

<?php
declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Embeddable()
 */
class Currency
{
    /**
     * @var string
     *
     * @ORM\Column(name="code", type="string", length=3)
     */
    protected $code;

    public function __construct(string $code)
    {
        $this->code = $code;
    }

    public function getCode(): string
    {
        return $this->code;
    }
}
<?php
declare(strict_types=1);

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Embeddable()
 */
class Money
{
    /**
     * @var string
     *
     * @ORM\Column(name="amount", type="string", length=255)
     */
    protected $amount;

    /**
     * @var Currency
     *
     * @ORM\Embedded(class="App\Entity\Currency")
     */
    protected $currency;

    public function __construct(string $amount, Currency $currency)
    {
        $this->amount = $amount;
        $this->currency = $currency;
    }

    public function getAmount(): string
    {
        return $this->amount;
    }

    public function setAmount(string $amount): void
    {
        $this->amount = $amount;
    }

    public function getCurrency(): Currency
    {
        return $this->currency;
    }
}
<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\ProductRepository")
 */
class Product
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    protected $id;

    /**
     * @var Money
     *
     * @ORM\Embedded(class="App\Entity\Money")
     */
    protected $price;

    public function getId(): ?int
    {
        return $this->id;
    }
}

and if tried to use validator on entity Product

In PropertyMetadata.php line 40:
Property "price.currency" does not exist in class "App\Entity\Product"

Problem lays here

$metadata->addPropertyConstraint($mapping['declaredField'], new Valid());

Screenshot 2019-06-06 at 20 42 37

@xabbuh
Copy link
Member
xabbuh commented Jun 8, 2019

Status: Reviewed

@xabbuh
Copy link
Member
xabbuh commented Jun 8, 2019

see #31953

@fabpot fabpot closed this as completed Jun 11, 2019
fabpot added a commit that referenced this issue Jun 11, 2019
This PR was merged into the 4.3 branch.

Discussion
----------

[DoctrineBridge] fix handling nested embeddables

| Q             | A
| ------------- | ---
| Branch?       | 4.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #31911
| License       | MIT
| Doc PR        |

Commits
-------

37efa4b fix handling nested embeddables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants
0