Add New Attribute Metadata Driver #6538

Closed
opened 2026-01-22 15:34:44 +01:00 by admin · 8 comments
Owner

Originally created by @beberlei on GitHub (Sep 13, 2020).

Originally assigned to: @beberlei on GitHub.

For Doctrine ORM 2.8 we should add a metadata driver using Attributes, based off the AnnotationDriver with some adjustment to account for the missing nested support.

Idea:

  • Re-use Doctrine\ORM\Mapping\* annotation classes and add #[Attribute] as needed.
  • Flatten @JoinTable by introducing new InverseJoinColumn attribute
  • Flatten @Table by allowing Index and UniqueConstraint on the entity/class level.
  • Drop support for named queries and named native queries in Attribute based mapping driver due to their nesting complexity.
  • No support for association overrides in Attribute based mapping driver.
Originally created by @beberlei on GitHub (Sep 13, 2020). Originally assigned to: @beberlei on GitHub. For Doctrine ORM 2.8 we should add a metadata driver using Attributes, based off the AnnotationDriver with some adjustment to account for the missing nested support. Idea: - Re-use `Doctrine\ORM\Mapping\*` annotation classes and add `#[Attribute]` as needed. - Flatten `@JoinTable` by introducing new `InverseJoinColumn` attribute - Flatten `@Table` by allowing `Index` and `UniqueConstraint` on the entity/class level. - Drop support for named queries and named native queries in Attribute based mapping driver due to their nesting complexity. - No support for association overrides in Attribute based mapping driver.
admin added the New Feature label 2026-01-22 15:34:44 +01:00
admin closed this issue 2026-01-22 15:34:44 +01:00
Author
Owner

@beberlei commented on GitHub (Sep 13, 2020):

Problem with this approach is that without a constructor using parameters, IDEs will probably not autocomplete the named properties of attributes. This requires us to duplicate all attribute classes unless we find some clever magic, or adjust the Annotation DocParser case with has_constructor must be changed or broken in some way.

@beberlei commented on GitHub (Sep 13, 2020): Problem with this approach is that without a constructor using parameters, IDEs will probably not autocomplete the named properties of attributes. This requires us to duplicate all attribute classes unless we find some clever magic, or adjust the Annotation DocParser case with `has_constructor` must be changed or broken in some way.
Author
Owner

@lcobucci commented on GitHub (Sep 13, 2020):

Dropping named queries is a BC-break though

@lcobucci commented on GitHub (Sep 13, 2020): Dropping named queries is a BC-break though
Author
Owner

@beberlei commented on GitHub (Sep 13, 2020):

@lcobucci not for a new metadata driver

@beberlei commented on GitHub (Sep 13, 2020): @lcobucci not for a new metadata driver
Author
Owner

@lcobucci commented on GitHub (Sep 13, 2020):

Fair enough 👍

@lcobucci commented on GitHub (Sep 13, 2020): Fair enough 👍
Author
Owner

@beberlei commented on GitHub (Sep 13, 2020):

Currently Annotation DocParser does new $annotation($values); if a constructor is detected. This is based on the Annotation base class that existis in the library. We should have another use-case where it checks for constructor but not extending Doctrine\Common\Annotations\Nnnotation and in that case replicate named arguments behavior: @Column(name="foo") maps to a constructor __construct($name).

This is required so we can move all annotation classes to use a constructor in ORM 2.8.

@beberlei commented on GitHub (Sep 13, 2020): Currently Annotation `DocParser` does `new $annotation($values);` if a constructor is detected. This is based on the `Annotation` base class that existis in the library. We should have another use-case where it checks for constructor but not extending `Doctrine\Common\Annotations\Nnnotation` and in that case replicate named arguments behavior: ``@Column(name="foo")`` maps to a constructor ``__construct($name)``. This is required so we can move all annotation classes to use a constructor in ORM 2.8.
Author
Owner

@beberlei commented on GitHub (Sep 13, 2020):

The problem without this change is that we could not use ReflectionAttribute::newInstance then and also would probably confuse IDE autocomplete for attributes as they look for constructor arguments to suggest.

@beberlei commented on GitHub (Sep 13, 2020): The problem without this change is that we could not use `ReflectionAttribute::newInstance` then and also would probably confuse IDE autocomplete for attributes as they look for constructor arguments to suggest.
Author
Owner

@BenMorel commented on GitHub (Oct 13, 2020):

Looking forward to the attribute-based annotation driver! 👍

No support for association overrides in Attribute based mapping driver.

What's the issue with multiple #[AssociationOverride()] on the entity directly? (I've never understood the need for @AssociationOverrides in the first place, maybe a limitation in Doctrine Annotations?)

@BenMorel commented on GitHub (Oct 13, 2020): Looking forward to the attribute-based annotation driver! :+1: > No support for association overrides in Attribute based mapping driver. What's the issue with multiple `#[AssociationOverride()]` on the entity directly? (I've never understood the need for `@AssociationOverrides` in the first place, maybe a limitation in Doctrine Annotations?)
Author
Owner

@beberlei commented on GitHub (Apr 16, 2021):

This is merged with #8266

@beberlei commented on GitHub (Apr 16, 2021): This is merged with #8266
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6538