Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-761

Associations between string fields result in mismatched column definitions on owning side

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0-RC1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Using the latest master from github, defining a one-to-one or many-to-one relationship where the inverse side is a string of a specific length (i.e. other than the default 255 chars), the owning side column definition becomes a VARCHAR(255) (at least in MySQL) regardless of the length of the column on the other side of the relationship. I would expect the correct behavior would be for the column definitions to match on both sides. For example:

      /** @Entity */
      class foo {
      
          /**
           * @Id @Column(type="string", length=5)
           */
          protected $id;
      }
      
      /** @Entity */
      class bar {
          /**
           * @Id @Column(type="integer")
           */
          protected $id;
      
          /**
           * @OneToOne(targetEntity="Foo")
           * @JoinColumn(name="foo_id", referencedColumnName="id")
           */
          protected $foo;
      }
      
      /** @Entity */
      class baz {
          /**
           * @Id @Column(type="integer")
           */
          protected $id;
      
          /**
           * @ManyToOne(targetEntity="Foo")
           * @JoinColumn(name="foo_id", referencedColumnName="id")
           */
          protected $foo;
      }
      

      Resulting SQL from schematool:

      CREATE TABLE foo (id VARCHAR(5) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;
      CREATE TABLE bar (id INT NOT NULL, foo_id VARCHAR(255) DEFAULT NULL, UNIQUE INDEX bar_foo_id_uniq (foo_id), PRIMARY KEY(id)) ENGINE = InnoDB;
      CREATE TABLE baz (id INT NOT NULL, foo_id VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;
      ALTER TABLE bar ADD FOREIGN KEY (foo_id) REFERENCES foo(id);
      ALTER TABLE baz ADD FOREIGN KEY (foo_id) REFERENCES foo(id)
      

      Expected result:

      CREATE TABLE foo (id VARCHAR(5) NOT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;
      CREATE TABLE bar (id INT NOT NULL, foo_id VARCHAR(5) DEFAULT NULL, UNIQUE INDEX bar_foo_id_uniq (foo_id), PRIMARY KEY(id)) ENGINE = InnoDB;
      CREATE TABLE baz (id INT NOT NULL, foo_id VARCHAR(5) DEFAULT NULL, PRIMARY KEY(id)) ENGINE = InnoDB;
      ALTER TABLE bar ADD FOREIGN KEY (foo_id) REFERENCES foo(id);
      ALTER TABLE baz ADD FOREIGN KEY (foo_id) REFERENCES foo(id)
      

      This bug is possibly related to DDC-755 except these associations don't involve integers.

        Issue Links

          Activity

          Hide
          Benjamin Eberlei added a comment -

          fixed (should be!)

          Show
          Benjamin Eberlei added a comment - fixed (should be!)

            People

            • Assignee:
              Benjamin Eberlei
              Reporter:
              Marc Hodgins
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: