Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-477

Schema tool does not support STI - attempts duplicate table creation

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA1
    • Fix Version/s: 2.0-BETA1
    • Component/s: Tools
    • Security Level: All
    • Labels:
      None

      Description

      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.

        Issue Links

          Activity

          Hide
          Benjamin Eberlei added a comment -

          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.

          Show
          Benjamin Eberlei added a comment - 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.
          Hide
          Roman S. Borschel added a comment -
          Show
          Roman S. Borschel added a comment - 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
          Hide
          David Abdemoulaie added a comment - - edited

          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

          Show
          David Abdemoulaie added a comment - - edited 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
          Hide
          Benjamin Eberlei added a comment -

          Can you paste the complete SQL?

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

          Show
          Benjamin Eberlei added a comment - Can you paste the complete SQL? You can call $em->getConfiguration()->setSQLLogger(new EchoSqlLogger()); to print it
          Hide
          Benjamin Eberlei added a comment -

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

          Show
          Benjamin Eberlei added a comment - plus add a new issue please, this is pretty different to the orignal one.

            People

            • Assignee:
              Guilherme Blanco
              Reporter:
              David Abdemoulaie
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: