mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-871: @Version causes cascading to behave strangely #1079
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Nov 10, 2010).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user felicitus:
As promised, I'm working on a tutorial for Doctrine2 in combination with versioning (if you are interested, feel free to look at http://piratenpad.de/0keOSIyxBy ). I noticed that the following example (loosely based on Benjamin's versioning blog post a while ago) does odd things. This example is written using the latest GIT version, which includes the fixes from Benjamin for Ticket DDC-870.
The code works without a problem, but if you have a look at the database after running the invocation code, you'll notice that "version" in the table SimpleTestVersion contains always 1. The strange thing is that the "content" column is updated correctly. I added some debug code to the constructor of SimpleTestVersion, and the passed object really contains the current version, so the SimpleTestVersion's properties are set correctly.
@doctrinebot commented on GitHub (Nov 10, 2010):
Comment created by @beberlei:
SimpleTestVersion has no @Version tag, and you don't need to call ->persist() for entities that are alraedy known to doctrine to update them. Does that fix your problem?
Your code should only increment the version of SimpleTest despite of the "cascade" though, since the SimpleVersionTest does not change (it doesnt get udpated).
@doctrinebot commented on GitHub (Nov 10, 2010):
Comment created by felicitus:
Why I'm omitting @version in SimpleTestVersion:
SimpleTestVersion has no @Version tag, because versioning takes place in SimpleTest. SimpleTestVersion just stores copies of old versions. Since it seems that if you add @version to a property, it gets ignored by Doctrine's inserts (another bug report, or feature request, will follow). Or to be more precise: Set @version on fieldName, and doctrine doesn't do INSERT INTO table SET fieldName=version, but instead does an additional update statement and relies that fieldName's default value is set to 1. This is perfectly okay with me and this is not the issue. My example is similar as in your blog post; you did it actually the same way (and it didn't work there, either :)) The blog post I'm referring to is http://www.doctrine-project.org/blog/doctrine2-behaviours-nutshell
You're right, the multiple $em->persist calls are a mistake, but the (IMHO wrong) behavior doesn't change. I'll try to be a bit more precise:
Updated test code with a more precise comment:
@doctrinebot commented on GitHub (Nov 10, 2010):
Comment created by felicitus:
It seems that either I have a major misunderstanding of how Doctrine2 works, or there is a big bug.
I've rewritten the classes above to avoid relations. What I wish to achieve is that every time SimpleTest gets persisted or updated, a new SimpleTestVersion is created.
Doctrine2 creates a new SimpleTestVersion for the first time I call persist() then flush(), but not for subsequent calls to flush(). The logVersion() method is actually called.
Same invocation code as in my last comment. Maybe Doctrine2 becomes confused about another persist call during a flush() operation? I'll file another bug about that issue, since I believe Doctrine2 should either throw an Exception or do the persist with an additional flush.
@doctrinebot commented on GitHub (Nov 10, 2010):
Comment created by @beberlei:
adding new associations in lifecycle events prepersist is not allowed, please see the onFlush event.
@doctrinebot commented on GitHub (Nov 10, 2010):
Issue was closed with resolution "Invalid"
@doctrinebot commented on GitHub (Nov 10, 2010):
Comment created by felicitus:
That enlightens the problem a bit. Maybe you should add a notice to your post on http://www.doctrine-project.org/blog/doctrine2-behaviours-nutshell stating that this is outdated. On the other hand, shouldn't Doctrine2 complain if you attempt to persist something during events?