Skip to content

Loading…

DDC-1218: Generator disappear with mappedSuperclass and in others common inheritance's cases #1825

Closed
doctrinebot opened this Issue · 6 comments

2 participants

@doctrinebot

Jira issue originally created by user ndm:

With mapped superclass the id lost autoincrement. I've test with yaml and annotation this is the same.

An example with yaml entities :

Document:
  type: mappedSuperclass
  fields:
    mimetype: { type: string, length: 255 }
    filename: { type: string, length: 255 }

Image:
  type: entity
  fields:
    id: { type: integer, id: true, generator: { strategy: AUTO } }

The id in the table Image lost autoincrement.

@doctrinebot

Comment created by ndm:

The problem is in file doctrine/lib/Doctrine/ORM/Mapping, a solution, with just one change could be
:

    protected function loadMetadata($name)
    {
        if ( ! $this->initialized) {
...
        // Move down the hierarchy of parent classes, starting from the topmost class
...
            // Invoke driver
            try {
                $this->driver->loadMetadataForClass($className, $class);
            } catch (ReflectionException $e) {
                throw MappingException::reflectionFailure($className, $e);
            }
//Change
            if ($parent) {
//To
            if ($parent && ! $parent->isInheritanceTypeNone()) {
//EndChange
                if ($parent->isIdGeneratorSequence()) {
...
        }
@doctrinebot

Comment created by ndm:

I have seen the resolution in doctrine later version, so i hesitate to close this issue.

But i'm sure that the solution in place will not resolve all situation.

By example, if the superclass isn't mapped but an entity with joined, this doesn't work properly, and you lost the id and the generator of the childclass. Another exemple, you want a mapped with generator, and subclass which don't indicate id, you can't the generator isn't include, and the id is required in the subclass.

The code actually work just for same table proposition, and not good, because with same table you must indicate an not used id in the child class ( why an id is an obligation!!!, Sql permit to have table without id).

If somebody read this, i propose a solution for inherited class with another schema,

Each propositions are with a class inheriting from superclass :

####Schema for joinedclass.
In this case generator are leave in the same functions

table_class
  class_id -> **self generator**
table_link
  class_id
  class_discriminent
  superclass_id
table_superclass
  superclass_id -> **self generator**

or better and closest from the actual solution ( with obligation to have different id name)

table_class
  class_id -> **self generator**
  superclass_id
table_superclass
  superclass_id -> **self generator**
  discriminator

####Schema for same table
Not exactly the actual behavior but very near

table_class
   class_id autogenerate (or not exist)
   superclass*id (autogenerate with concatenation class*id and discr or not exit)

The better for me :

table_class
    superclass_id

####Schema for mapped

table_class
  class_id  <--- if exist (not obligatory)
  superclass*id <--- if class_id not exist, the generator from superclass*id
                                    if class*id exist, the generator from class*id

Even with there ideas, the possibility to have more than one generator method could be usefull. (i know that autoincrement can be use just one time). A solution, could be to add generator to field an not to entity in a first time, and treat generator at the end of the process not in the same place that the fields.

So if you read this thank and aufwiedersehen.

@doctrinebot

Comment created by @beberlei:

Fixed

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by ndm:

Thanks :)

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.1 milestone
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
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.