-
-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow LinkOptional - style FK constraints #1142
Comments
The following should work for single keys: var v *string
created, err := client.Post.FindUnique(
Post.ID.Equals("a"),
).Update(
Post.Author.Link(
User.ID.EqualsIfPresent(v),
),
).Exec(ctx)
if err != nil {
t.Fatalf("fail %s", err)
} Probably a LinkOptional would be better though; and it would also work with composite keys |
This is fine when the record exists already, however it forces a secondary lookup once you want to create a record and optionally link it to multiple tables depending on whether a FK is present, unless I'm misunderstanding the API which is highly likely |
Hm can you maybe provide an example code of how you would do it right now and how you would wish to do it? So I can fully understand your use-case. |
As discussed offline on discord, it is possible do a CreateOne operation directly and use something like report, err = client.Report.CreateOne(
db.Report.Workspace.Link(
db.Workspace.ID.Equals(workspaceId),
),
db.Report.Repository.Link(
db.Repository.ID.EqualsIfPresent(repositoryId),
),
... which addresses the constraint |
It is possible to have a FK constraints that are potentially empty in prisma, similar to the following
When emitting
Create
andUpsert
directives,Link
operations where an empty string is passed will fail in the attempt to convert to a UUID. As a result, one needs to be creating more complex if/else conditions to account for possibly empty foreign keys. It would be useful to either expose aLinkOptional
directive or equivalent to allow users to create a singleCreate
orUpsert
statementThe text was updated successfully, but these errors were encountered: