1

I'm trying to use Doctrine 2 event callbacks to create new related entities, but running into some issues. I'm sure this approach is horribly wrong, but here's the background:

I basically have a Document entity, and a Log entity, when a new Document is created I'm using a prePersist callback to create a related Log entity with a "created" status. This works.

I also want to create a related Log entity with an "updated" status when changes are made, I've tried to use preUpdate to add these related entities, but as expected from reading the docs, it doesn't work:

Changes to associations of the updated entity are never allowed in this event, since Doctrine cannot guarantee to correctly handle referential integrity at this point of the flush operation.

http://docs.doctrine-project.org/en/2.0.x/reference/events.html

So my question is, what's the correct way to do this?

Jack Sleight
  • 17,010
  • 6
  • 41
  • 55

0 Answers0