-
-
Notifications
You must be signed in to change notification settings - Fork 448
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
Add entity annotation sample #438
Conversation
Took me a while to figure out you have to define the entity listener as annotation as well.
Afaik this is not what you should have to do. Registering the listener should be enough. |
What do you call "registering"? The annotation in the entity or the service definition? |
The service definition with the right tag ( |
I agree, the Doctrine documentation also states this. If people read about this feature on the bundle documentation it will not work when just the example is copied. |
Could it be that your installed version of the DoctrineBundle simply does not contain this compiler pass (unknown tags don't trigger errors, but will silently be ignored)? |
No the service does gets registered with the resolver, that is not the problem. But without the annotation, there is no link between the entity class and the listener, so Doctrine cannot know where the listener can be applied to. |
Don't you configure that with the entity attribute of the tag? |
Hmm, I have not tried that, didn't know it existed (so basically, another issue). It looks like you have to define a tag for each event this way (like the Anyway, the documentation could be extended with all of these options, there are a bunch of ways to do this apparently. |
If I add the services:
user_listener:
class: \UserListener
tags:
- { name: doctrine.orm.entity_listener, event: postLoad, entity: 'AppBundle\Entity\User' } Even if this would work it only allows listening to one event. The |
Well, but if the listeners does not work as expected, it should rather be fixed than providing some documentation that just works around this. |
Works fine without annotations since #298 but Check your |
Should this be merged and if yes is it ready? |
@davidfuhr Thanks merged in #576 |
Took me a while to figure out you have to define the entity listener as
annotation as well.