Problem
model ModelA {
id Int,
name String
bKind String //should matches a value that exists in ModelB.kind
}
model ModelB {
id Int,
name String
kind String //this is not unique and can't identify a single ModelB row
}
Unfortunately, AFAIK the only current way of describing a FK is through a @relation attribute that enforce matching an unique and effective object, that should be present in the linked model.
That's not ideal when one just want to ensure scalars consistency from the described zmodel.
Proposal
A new @foreign attribute allowing to describe a simple FK constraint would be nice
i.e:
model TableA {
id Int,
name String
bKind String @foreign(fields:[bKind], references:[kind], from: ModelB)
}
Describe alternatives you've considered
Adding custom SQL to create the FK in a migration. But, IMHO, the ORM model should allow describing simple FK and abstract their creation.
Problem
Unfortunately, AFAIK the only current way of describing a FK is through a
@relationattribute that enforce matching an unique and effective object, that should be present in the linked model.That's not ideal when one just want to ensure scalars consistency from the described zmodel.
Proposal
A new
@foreignattribute allowing to describe a simple FK constraint would be nicei.e:
Describe alternatives you've considered
Adding custom SQL to create the FK in a migration. But, IMHO, the ORM model should allow describing simple FK and abstract their creation.