Description
Symfony version(s) affected
5.4, 6.0
Description
Autodetecting mapping type works based on @Entity
annotation, but it ignores @Embeddable
annotation. In result, Symfony crashes with a
Class App\ValueObject\Foo is not a valid entity or mapped super class
error.
How to reproduce
PHP 8.0+.
- Add to
config/packages/doctrine.yaml
these lines:
App\ValueObject:
is_bundle: false
dir: '%kernel.project_dir%/src/ValueObject'
prefix: 'App\ValueObject'
alias: App
Docs says annotation
is a default value for type
, so omitting it.
https://symfony.com/doc/current/reference/configuration/doctrine.html#mapping-configuration
- Add a value object to
src\ValueObject
using an@Embeddable
annotation:
<?php
namespace App\ValueObject;
use Doctrine\ORM\Mapping as ORM;
/** @ORM\Embeddable */
class Foo
{
}
-
Use this value object somewhere in your entities.
-
Symfony crashes with an error:
Class App\ValueObject\Foo is not a valid entity or mapped super class
because it detects annonation type by presence#[.*Entity
or* @.*Entity
, but notEmbeddable
.
And it fallbacks toattribute
instead ofannonation
on PHP8.
Possible Solution
$this->getMappingObjectDefaultName()
should return (?:Entity|Embeddable)
instead of Entity
I guess.
https://github.com/symfony/symfony/blob/6.1/src/Symfony/Bridge/Doctrine/DependencyInjection/AbstractDoctrineExtension.php#L292
Additional Context
No response