|
There is a case in which duplicate FK constraint is created. They the duplication happens if we have Many To Many relation between an Entity A and an Entity B (one way) and at the same time Entity C which extends B to have direct relation to A(the inverse way) .
I have two entities: Site and Catalog in a module. The idea here is that Catalog is not aware it is used of a site. The site contains a collection of catalogs mapped as ManyToMany, the catalog doesn't contain colleciton of sites. I have the successor of Catalog called ContentCatalog which is aware of Sites since it will contain content and I have the inverse side defined there.
The generated SQL looks like :
alter table site_content_catalog add constraint FKgw4j8ogdbo7iicb8jd6fvylye foreign key (site_pk) references site (pk);
alter table site_content_catalog add constraint FKs1w0m2txojv9djjqe56lmqf40 foreign key (catalog_pk) references catalog (pk);
alter table site_content_catalog add constraint FKs1w0m2txojv9djjqe56lmqf40 foreign key (catalog_pk) references catalog (pk);
As you can see the last FK is the same as the previous one.
|