Skip to content

Loading…

DDC-761: Associations between string fields result in mismatched column definitions on owning side #5275

Closed
doctrinebot opened this Issue · 3 comments

2 participants

@doctrinebot

Jira issue originally created by user mjh_ca:

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.

@doctrinebot

Comment created by @beberlei:

fixed (should be!)

@doctrinebot

Issue was closed with resolution "Fixed"

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