[DBAL-812] SchemaTool ignores multi-columns (composite) indexes when creating a foreign key Created: 13/Feb/14 Updated: 15/Feb/14
|Reporter:||Peter Huynh||Assignee:||Steve Müller|
When using the schema tool to generate the differences between the db and the entities, I notice the following:
ALTER TABLE sales ADD CONSTRAINT FK_36D222EF603EE73 FOREIGN KEY (vid) REFERENCES vendor (id);
Normally, it doesn't bother me, however I have had an existing composite index consists of (vid, submit). This leads to the redundant index IDX_36D222EF603EE73 and therefore forcing unnecessary overheads.
It would be nice to have a mean to disable this from happening.
The code in question can be found at https://github.com/doctrine/dbal/blob/594e326bd58d1d7af578f0dc3143655b9d119d45/lib/Doctrine/DBAL/Schema/Table.php#L543.
A helpful member from #doctrine IRC also pointed out that it does not check the unique constraints also.
|Comment by Marco Pivetta [ 13/Feb/14 ]|
Just a hint on this: looks like the current logic just checks hashed indexes, ignoring the "uniq" prefixed indexes to avoid duplicates.
|Comment by Steve Müller [ 15/Feb/14 ]|
Peter Huynh I get the point here. However after having a quick look into this it seems this behaviour exists for a good reason. See here: https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Schema/Index.php#L191-L195
|Comment by Peter Huynh [ 15/Feb/14 ]|
I fully understand your reservation.
Thanks for looking into things.