Reputation: 2486
In Symfony using doctrine, whats the best way to run a certain function just before an entity is saved/persisted to the database. I only want it to be run once in its lifetime so I guess the construction function is no good.
Upvotes: 0
Views: 829
Reputation: 31548
or
You can either call that function just before the $em->persist($entity);
function in the controller.
But PrePersist
is the cleaner way but for testing and small stuff , you can put before the save function
Upvotes: 0
Reputation: 12727
Use LifecycleCallback named PrePersist
as explained in the doc : http://symfony.com/doc/current/book/doctrine.html#lifecycle-callbacks
Upvotes: 1