Skip to content

[Feature Request] a foreign constraint attribute for scalar fields not implying a relation mapping #2638

@jaenyf

Description

@jaenyf

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions