Skip to content

[DoctrineBridge] Attribute notation for entity in bundles is not recognized #43753

@cinamo

Description

@cinamo

Symfony version(s) affected

5.3

Description

When loading a bundle with a Doctrine entity, this entity is automatically recognized if auto_mapping: true is set in the Doctrine DBAL configuration. If you use annotations (/** @ORM\Entity */), this will work well. However, if you use the new Attributes to define the entity and its properties (#[ORM\Entity]) this is not recognized by the DoctrineBridge.

How to reproduce

Create an entity in a bundle and define its Entity status with an attribute:

<?php

declare(strict_types=1);

namespace RedAnt\EventSourcingBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use RedAnt\EventSourcingBundle\Entity\Repository\ProjectionsRepository;

#[ORM\Entity(repositoryClass: ProjectionsRepository::class)]
final class ProjectionState
{
 // ...
}

This entity class is then not picked up by the Doctrine schema upgrade tool.

Possible Solution

The AbstractDoctrineExtension in the DoctrineBridge already has a method for detecting the correct annotation type for entities in a folder (using a regex on the entity classes). We should separate this out into a new method detectMappingType and also using it when detecting the metadataDriver for that bundle directory.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions