Skip to content
Advertisement

How persist new Entity in Doctrine 2 prePersist method?

I’ve a Entity with @HasLifecycleCallbacks for define prePersist and preUpdate method.

My PrePersist method is

JavaScript

I hoped that this could persist my Field entities, but my table is empty. Should I use an EntityManager? How can I retrieve it within my Entity?

Advertisement

Answer

You need to use the LifecycleEventArgs to get EntityManager and be able to persist Entity in prePersist method. You can retrieve it like that :

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement