Attribute on traits #6792

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

Originally created by @jurriaanr on GitHub (Jul 27, 2021).

Feature Request

There was a question/discussion before about annotations on traits (f.e. the HasLifecycleCallbacks annotation):
https://github.com/doctrine/orm/pull/1517

The same thing would now apply to attributes. Right now using an attribute on a trait does not seem to work:

#[ORM\HasLifecycleCallbacks]
trait Timestampable
{
   ....
}

Right now the attribute needs to be on the Entity using the trait. Following the same principle as the above annotation example attributes on a trait should be parsed as well.

Q A
New Feature yes
RFC no
BC Break no

Summary

parse attributes on trait as if they were on class

Originally created by @jurriaanr on GitHub (Jul 27, 2021). ### Feature Request There was a question/discussion before about annotations on traits (f.e. the HasLifecycleCallbacks annotation): https://github.com/doctrine/orm/pull/1517 The same thing would now apply to attributes. Right now using an attribute on a trait does not seem to work: ``` #[ORM\HasLifecycleCallbacks] trait Timestampable { .... } ``` Right now the attribute needs to be on the Entity using the trait. Following the same principle as the above annotation example attributes on a trait should be parsed as well. | Q | A |------------ | ------ | New Feature | yes | RFC | no | BC Break | no #### Summary parse attributes on trait as if they were on class
admin added the New Feature label 2026-01-22 15:38:48 +01:00
Author
Owner

@Safranil commented on GitHub (Sep 22, 2021):

Hi,

I need the same. I have a trait for an UUID that is generated at persist time and it would be useful to set the HasLifecycleCallbacks Attribute/Annotation on the trait instead of all classes using this trait.

@Safranil commented on GitHub (Sep 22, 2021): Hi, I need the same. I have a trait for an UUID that is generated at persist time and it would be useful to set the `HasLifecycleCallbacks` Attribute/Annotation on the trait instead of all classes using this trait.
Author
Owner

@derrabus commented on GitHub (Sep 22, 2021):

TIL: You can have attributes on traits. 🤯

@derrabus commented on GitHub (Sep 22, 2021): TIL: You can have attributes on traits. 🤯
Author
Owner

@e-vural commented on GitHub (Nov 14, 2022):

I am working on symfony 6 and php 8. If i use trait inside entity, columns dont show in db. But when i use php 7.4 , i have no problem.
image

image

created_at and updated_at columns don't show when i force db.

@e-vural commented on GitHub (Nov 14, 2022): I am working on symfony 6 and php 8. If i use trait inside entity, columns dont show in db. But when i use php 7.4 , i have no problem. <img width="878" alt="image" src="https://user-images.githubusercontent.com/11753784/201598843-945c4249-85cb-49f0-93b8-765a19d74346.png"> <img width="925" alt="image" src="https://user-images.githubusercontent.com/11753784/201598739-ab54a1c5-5a1f-4154-8270-4ad043fccdfa.png"> created_at and updated_at columns don't show when i force db.
Author
Owner

@e-vural commented on GitHub (Nov 14, 2022):

I found the problem. https://github.com/symfony/symfony/issues/46003#issuecomment-1313228905

@e-vural commented on GitHub (Nov 14, 2022): I found the problem. https://github.com/symfony/symfony/issues/46003#issuecomment-1313228905
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6792