Skip to content

Loading…

DDC-790: Generating entities with cli failed on inheritated entities due missing PK #5306

Closed
doctrinebot opened this Issue · 6 comments

2 participants

@doctrinebot

Jira issue originally created by user edke:

While generating entities with:

./doctrine orm:generate-entities --generate-methods=true ../tmp/entities

getting MappingException: No identifier/primary key specified for Entity 'Entities\Admin'. Every Entity must have an identifier/primary key.

Admin is class inheritated, definition included:

Person: http://pastebin.com/5r9fXrAu
Admin: http://pastebin.com/51BcRZWZ

@doctrinebot

Comment created by @beberlei:

You cannot generate entities in an inheritance hierachy currently

@doctrinebot

Comment created by @beberlei:

AFter having looked at the mappings, how do you plan to generate methods from annotated entities? I think the entity generator won't allow that, jwage?

@doctrinebot

Comment created by @jwage:

The problem with everything is that the inheritance hierarchy is not mapped, instead it is read at runtime from the classes themselves. So, when you're generating the initial entities from the mapping information, you don't have that information, so we can't properly generate a class with the "class ClassName extends SomeOtherClass" because we simply don't know it.

To work around it all you have to do is manually create the file with the empty class inside of it, extending the class you want. When you run the orm:generate-entities again, it can properly read the subclasses of every entity and the generation will update the classes existing classes properties and methods instead of trying to generate a new class.

Does that clear things up? I think the only way to fix it would be to allow the user to manually specify the all the inheritance information in the mapping information instead of reading it at run-time. That way we have all the information about some entities even before the actual classes exist and we can generate the right code then.

Thoughts?

@doctrinebot

Comment created by @jwage:

Benjamin, yes it is possible. But like I mentioned above we don't know what class an entity extends until the class is created. You have no way to say in the mapping information that this entity extends this class.

If you have an entity already created with just the annotated properties, and you run the command to generate entities it will update the class adding the methods to the class. If you were to add a new property to the class and annotate and run the command again, it would only add the 2 new methods to the bottom of the class.

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot

Comment created by edke:

This is really what I'm looking for. I create classes, fill them with properties and define annotations for them. Then I run cli tool to generate all methods (getters and setters) for classes to skip the boring part of creating entity. Then if required, I modify getters and setters.

Only problem was that it failed on classes that were inheritated because they were missing primary keys.

As a workaround while generating methods for new entities, I moved away from project inheritated entities and after generating I moved them back.

@jwage jwage was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.0-BETA4 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.