Why the foreign key for one-to-one is the same for foreign key for one-to-many:
one-to-one
-- begin TAXONOMY_LONGNAMES
alter table TAXONOMY_LONGNAMES add constraint FK_TAXONOMY_LONGNAMES_ON_ID_TAXONOMIC_UNITS foreign key (ID_TAXONOMIC_UNITS_ID) references TAXONOMY_TAXONOMIC_UNITS(ID)^
create index IDX_TAXONOMY_LONGNAMES_ON_ID_TAXONOMIC_UNITS on TAXONOMY_LONGNAMES (ID_TAXONOMIC_UNITS_ID)^
-- end TAXONOMY_LONGNAMES
one-to-many
-- begin TAXONOMY_GEOGRAPHIC_DIV
alter table TAXONOMY_GEOGRAPHIC_DIV add constraint FK_TAXONOMY_GEOGRAPHIC_DIV_ON_ID_TAXONOMIC_UNITS foreign key (ID_TAXONOMIC_UNITS_ID) references TAXONOMY_TAXONOMIC_UNITS(ID)^
create index IDX_TAXONOMY_GEOGRAPHIC_DIV_ON_ID_TAXONOMIC_UNITS on TAXONOMY_GEOGRAPHIC_DIV (ID_TAXONOMIC_UNITS_ID)^
-- end TAXONOMY_GEOGRAPHIC_DIV
Is not necessary a unique for ID_TAXONOMIC_UNITS_ID field for one-to-one?
I saw also this aspect for SAMPLE_CUSTOMER table for sample https://demo2.cuba-platform.com/model/#!
I try to force added option unique = true in Longnames entity, like this :
Hi,
You can create a unique index if you want to maintain consistency on database level. It can be declared manually with @Index JPA annotation, or with help of Entity Designer in Studio.
P. S. CUBA is considered a legacy product, it isn’t a great idea to use it for starting a new project. Consider using Jmix instead: Get Started - Jmix
Thank you Alexander for your answer,
Now, I added constraint manually for table taxonomy_longnames in database alter table taxonomy_longnames add constraint uq_id_taxonomic_units_id unique(id_taxonomic_units_id);, after that appear ok, look:
P.S. I started the project in Cuba because I also have others projects in Cuba and I need taxonomy in this started projects. In this moment I requested funds to management to acquire Jmix Studio after that I have in plan to export the projects in Jmix. But is not very easy, because we are non profit company.
and after that I have two unique index, one with my name another with “automatic name”:
-- begin TAXONOMY_LONGNAMES
alter table TAXONOMY_LONGNAMES add constraint FK_TAXONOMY_LONGNAMES_ON_ID_TAXONOMIC_UNITS foreign key (ID_TAXONOMIC_UNITS_ID) references TAXONOMY_TAXONOMIC_UNITS(ID)^
create unique index IDX_TAXONOMY_LONGNAMES_UK_ID_TAXONOMIC_UNITS_ID on TAXONOMY_LONGNAMES (ID_TAXONOMIC_UNITS_ID) where DELETE_TS is null ^
create unique index INDEX_ID_TAXONOMIC_UNITS_ID on TAXONOMY_LONGNAMES (ID_TAXONOMIC_UNITS_ID) where DELETE_TS is null ^
create index IDX_TAXONOMY_LONGNAMES_ON_ID_TAXONOMIC_UNITS on TAXONOMY_LONGNAMES (ID_TAXONOMIC_UNITS_ID)^
-- end TAXONOMY_LONGNAMES