Details
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
- is duplicated by
-
DDC-755
Length of String column in a many to many bi-directional is 255 chars
-
fixed (should be!)