Skip to content

Loading…

DDC-873: @Version and Single Table #5396

Closed
doctrinebot opened this Issue · 5 comments

2 participants

@doctrinebot

Jira issue originally created by user felicitus:

In my previous Bug Report DDC-871 I'm using a separate table for versioning copies. However, if one wishes to keep all versions in a single table, this causes some headaches, since the field with @version can't be set by the developer (i.e. Doctrine2 does magic here).

I'll try to describe it with some meta code.

Let's say you have the class SingleTable, which has a property version marked with @version and @id, and also a property id marked with @id. I know this isn't the preferred way since it's a composite primary key, but in theory it would work. I'm managing the ID of the object myself, which works without a problem.

The problem is that once a field is marked with @version, it isn't set during an insert operation. Doctrine2 relies on the field's default value. This causes the following problems:

  • You can't start with an object version higher than 1.
  • If you wish to insert an older version (which is possible with my composite primary key example), you can't simply set the version - Doctrine2 does it's own magic, which fails at this point.

No matter if there will be a change to the @version behavior or not, it should be documented a bit better in the documentation. Once I know if it will be changed or not, I can contribute additional documentation for this.

@doctrinebot

Comment created by @beberlei:

Yes @Version and @Id are not allowed. This should just throw an exception.

@doctrinebot

Comment created by felicitus:

As I'm already working on some documentation things, I will add this to the documentation and maybe also add some code to throw an Exception.

@doctrinebot

Comment created by felicitus:

Just created a pull request for this (I added the bugfix + testcase), feel free to close after pull.

@doctrinebot

Comment created by @beberlei:

Implemented exception on this wrong usage.

@doctrinebot

Issue was closed with resolution "Fixed"

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0-RC1 milestone
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.