DDC-477: Schema tool does not support STI - attempts duplicate table creation #4980

Closed
doctrinebot opened this Issue Mar 25, 2010 · 7 comments

2 participants

@doctrinebot

Jira issue originally created by user @hobodave:

Sample entities:

/****
 * @Entity
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="type", type="string")
 * @DiscriminatorMap({"User" = "User", "Group" = "Group"})
 * @Table(name="user")
 */
class User extends Principal
{}

/****
 * @Entity
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="type", type="string")
 * @DiscriminatorMap({"User" = "User", "Group" = "Group"})
 * @Table(name="user")
 */
class Group extends Principal
{}

CLI Results:

daves-macbookpro:sandbox hobodave$ ./doctrine Orm:schema-tool --create --dump-sql
Doctrine Command Line Interface

Orm:schema-tool => The table with name 'user' already exists.

I would expect it to be intelligent enough to not try to create the user table twice.

@doctrinebot

Comment created by @beberlei:

I think the mapping is wrong, you effectivly define STI twice. It has to be done on the most parent class, i.e. on Principal.

@doctrinebot

Comment created by romanb:

Benjamin is right. This is also stated in the docs: http://www.doctrine-project.org/documentation/manual/2_0/en/inheritance-mapping#single-table-inheritance

@doctrinebot

Comment created by @hobodave:

A recent update broke all support for STI.

Now the following does not work:

/****
 * @MappedSuperclass
 * @InheritanceType("SINGLE_TABLE")
 * @DiscriminatorColumn(name="type", type="string")
 * @DiscriminatorMap({"User" = "User", "Group" = "Group"})
 * @Table(name="user")
 */
abstract class Principal
{}
/****
 * @Entity
 */
class Group extends Principal
{}
/****
 * @Entity
 */
class User extends Principal
{}

Attempting to use orm:schema-tool:create results in the following error:

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Group (user_id INT NOT NULL, username VARCHAR(45) NOT NULL, password VARCHAR(40)' at line 1

@doctrinebot

Comment created by @beberlei:

Can you paste the complete SQL?

You can call $em->getConfiguration()->setSQLLogger(new EchoSqlLogger()); to print it

@doctrinebot

Comment created by @beberlei:

plus add a new issue please, this is pretty different to the orignal one.

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.0-BETA1 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment