[DataModel] Compound Foreign Keys and Index Definitions
See original GitHub issueThe @@index definition currently has to refer to datamodel fields, but in the case of compound foreign keys two or more database fields are collapsed into one datamodel field. The indexes on the other hand can refer to the underlying database fields which are not in the datamodel (apart from being in the @map).
The @@unique definition theoretically has the same issue, but since we do not render it in the case of relations but instead make the relation 1:1 this issue does not surface.
Issue Analytics
- State:
- Created 4 years ago
- Comments:16 (16 by maintainers)
Top Results From Across the Web
Foreign Keys | Enterprise Architect User Guide - Sparx Systems
A Foreign Key defines a column (or a collection of columns) that enforces a relationship between two Tables. It is the responsibility of...
Read more >Defining Composite Primary and Foreign Keys - IBM
A composite key specifies multiple columns for a primary-key or foreign-key constraint. The next example creates two tables. The first table has a...
Read more >Indexes on foreign keys - Ask TOM
I have read several books which have repeatedly mentioned creating indexes on foreign keys. I know one advantage is that it eliminates table-level...
Read more >16.20 - Foreign Keys - Teradata Vantage NewSQL Engine
A foreign key is an attribute set in one relation based on an identical attribute set that acts as a primary or alternate...
Read more >Glossary - ER/Studio Data Architect - Embarcadero DocWiki
A type of entity in which no foreign keys participate in its primary key. Index. A database object used to enforce unique values...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I would like to suggest one further simplification to the suggested syntax. To me the current syntax proposal feels very heavy for those reasons:
@relation(fields: [sub_relation_field]) @map(["relation_column"])the name seems to be irrelevant.I would like to suggest an approach with which we could stick to the two types scalar and relation field. My suggestion is to turn relation fields into a completely virtual concept. Here are the rules i have in mind:
FOREIGN KEY (a, b) REFERENCES OtherTable(col1, col2)is turned intorelationField OtherTable @relation(fields: [a,b], references: [col1, col2].Here’s a more detailed example:
SQL schema
corresponding Prisma schema
Should be fixed by https://github.com/prisma/prisma-engines/pull/621