Skip to content
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

Merged
merged 1 commit into from
Oct 17, 2016
Merged

Add entity annotation sample #438

merged 1 commit into from
Oct 17, 2016

Conversation

davidfuhr
Copy link
Contributor

Took me a while to figure out you have to define the entity listener as
annotation as well.

Took me a while to figure out you have to define the entity listener as
annotation as well.
@xabbuh
Copy link
Member

xabbuh commented Jun 19, 2015

Afaik this is not what you should have to do. Registering the listener should be enough.

@davidfuhr
Copy link
Contributor Author

What do you call "registering"? The annotation in the entity or the service definition?

@xabbuh
Copy link
Member

xabbuh commented Jun 21, 2015

The service definition with the right tag (doctrine.entity_listener).

@pkruithof
Copy link
Contributor

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.

@xabbuh
Copy link
Member

xabbuh commented Jul 7, 2015

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)?

@pkruithof
Copy link
Contributor

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.

@xabbuh
Copy link
Member

xabbuh commented Jul 7, 2015

Don't you configure that with the entity attribute of the tag?

@pkruithof
Copy link
Contributor

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 event_listener tag), while when you tag the entity, you can use annotations like @PrePersist on the listener.

Anyway, the documentation could be extended with all of these options, there are a bunch of ways to do this apparently.

@davidfuhr
Copy link
Contributor Author

If I add the entity and the event attribute (only entity does not work) the EntityListenerPass enters the attachToListener() method but fails to retrieve the listener from the conainer:

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 @EntityListeners annotation allows listening to all entity events.

@xabbuh
Copy link
Member

xabbuh commented Jul 29, 2015

Well, but if the listeners does not work as expected, it should rather be fixed than providing some documentation that just works around this.

@Ocramius Ocramius changed the title [DX] Add entity annotation sample Add entity annotation sample Jul 30, 2015
@meyerbaptiste
Copy link

Works fine without annotations since #298 but doctrine/orm must be >= 2.5.0. You can see the restriction here: DoctrineExtension.php#L434-L438.

Check your doctrine/orm version @davidfuhr.

@kimhemsoe
Copy link
Member

Should this be merged and if yes is it ready?

@mikeSimonson mikeSimonson merged commit 132e903 into doctrine:master Oct 17, 2016
@mikeSimonson
Copy link
Contributor

@davidfuhr Thanks merged in #576

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants