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
Preview feature feedback: Prisma field reference support (fieldReference
)
#15068
Comments
Request for references across tables from @danshapir:
|
hope it can do it with cross models. |
@matthewmueller with this new feature is the following valid? See #11646 for context! // For the given class (with ID `some-class-id`):
// - Get what school it's in
// - Get all classes in that school in the same year as the given class
prisma.db.class.findUnique({
select: {
year: true,
name: true,
school: {
select: {
name: true,
classes: {
select: { name: true },
where: { year: { equals: prisma.class.fields.year } }
}
}
}
},
where: { id: `some-class-id` }
}) |
As far as I can tell, this doesn't seem to work with
|
Any update for this feature? |
It is in preview. You can use it. It is documented here: https://www.prisma.io/docs/reference/api-reference/prisma-client-reference#compare-columns-in-the-same-table |
Thanks for the response! I meant to ask about using this feature for comparing columns in separate tables (as mentioned above). I guess this will be a separate issue/feature. Both are much needed. |
Ahhh - optimally someone open a new issue for that please. Much easier for us to track then. |
I think I found a bug: #16715 |
Hum looks like enum Locale {
en
ja
es
fr
...
}
// ...
localeDefault Locale
locale Locale if I try to match those .findMany({
where: {
locale: { equals: db.table.fields.localeDefault },
}
})
/*
Argument equals: Provided value prisma.table.fields.localeDefault of type LocaleFieldRefInput<Table> on prisma.findManyTable is not a Locale.
*/ Looks like a field reference is not a valid enum value, or it doesn't pass some form of validation. |
How about updating the value of a field from a referenced field? For example, for the table:
set value from the await prisma.table.updateMany({
where: {
remains: {
gt: prisma.table.fields.limit
}
},
data: {
remains: prisma.table.fields.limit
}
}); It would be very helpful to update a such case. |
It looks like the value of a referenced field can only be used directly right now. But I would like to do something like this: prisma.job.updateMany({
data: {
status: JobStatus.ABORTED,
stoppedAt: new Date(),
},
where: {
startedAt: {
lt: Date.now() - prisma.job.fields.timeoutMs,
},
status: JobStatus.STARTED,
}
}); Would it be possible to add support for such computations that make use of referenced fields? |
@kefniark: Thanks for bringing this to our attention. It should be fixed in the next release.
@aarbmx6s: We agree this is a valuable feature. While we don't plan on adding this feature just yet as we've got other priorities, feel free to persist this in a separate feature request so that it gets more visibility 🙏
@tslater: It's hard for me to tell without A code snippet but the TS definition you've shared suggests to me that you're trying to do the following: await prisma.model.findMany({
where: { field: prisma.model.otherField }
}) But this is not supported (yet). Try using the explicit await prisma.model.findMany({
where: { field: { equals: prisma.model.otherField } }
})
@livthomas: We agree this is a valuable feature. See similar issue here: #16715 (comment). While we don't plan on adding this feature just yet as we've got other priorities, feel free to persist this in a separate feature request so that it gets more visibility 🙏 |
Simply adding
This is before making any other code changes. Unfortunately I'm working with a large-ish project that makes it hard to distill this down into a minimal repro 😕 Does someone know how I would go about finding the root cause here so I can file an issue? |
@he-la Is there any way you could share your Prisma Schema with us, even privately if needed? |
const workflowsToTrigger = await db.workflow.findMany({
where: {
builderId: auditLog.builderId,
},
include: {
steps: {
where: {
workflowVersion: {
equals: db.workflow.fields.version,
},
},
},
},
}) I am trying to do something like this, find steps in a workflow that match the workflow's version number.
|
I would also love to be able to do this. |
Thank you everyone for the feedback 🙌🏼 We’re excited to announce that the We first introduced this feature in 4.5.0 to add the ability to compare columns on the same table. For example, the following query returns records where the await prisma.product.findMany({
where: {
quantity: { lte: prisma.product.fields.warnQuantity }
},
}) |
Does this feature work for a deeply related relation as well?
Can I do
|
Please open a discussion to ask this question. Thanks. |
Is there a solution to the multiple column references through and operation problem? For example:
I believe |
Please share your feedback about the
fieldReference
functionality released in v4.3.0 in this issue.=> Documentation
If you have any questions, don't hesitate to ask them in the
#prisma-client
channel in the Prisma Slack.The text was updated successfully, but these errors were encountered: