mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-3423: Column Ordering when creating tables using doctrine:schema:update #4224
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 (Dec 1, 2014).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user rajasaur:
When you have a Base class (annotated with @MappedSuperClass) having some columns, say, createdById, createdDateTime and child entities deriving from the BaseClass, the ordering of the SQL when running doctrine:schema:update looks like
createdById
createdDateTime
id
field1
field2
i.e. the columns of the Base class come up first and then that of the children. It looks odd when you write a SQL to insert into these tables because the default ordering is not what you expect (Which would be derived class columns first and then base class).
I looked into ClassMetadataFactory that adds the fields to the classmetadata and figured if we could move the following
$this->addInheritedFields($class, $parent);
$this->addInheritedRelations($class, $parent);
to after the point where the local fields are added to the classmetadata, this problem is solved.
It might be even better if we have an annotation to specify the Ordering of columns but nevertheless this will help in cases where the base class columns appear after the derived class columns.
Note: Did look into columnDefinition annotation to specify a "AFTER ", but that cannot be used during CREATE TABLE, only for ALTER TABLE and that too, its mysql specific.
@doctrinebot commented on GitHub (Mar 5, 2015):
Comment created by topor-grabowski:
This would be a great feature. I am using inheritance in the entity classes and have the same problem.
Even if this is not a common taks for ORM, but i simplifies your life;-)
@romainbriand commented on GitHub (Apr 20, 2020):
We can live without it of course but it would be a nice feature to have 👍
@itsjavi commented on GitHub (Feb 17, 2022):
I have the same problem when using traits or inheritance: the child class properties are put before the ones used in the use trait statements (which I expect to go first). My app shows the user the list of columns in a UI, so it's weird to see other columns before the
idfor example.I'm using the latest version of DBAL and the ORM 2.11.1