Select specific fields of included relationsYou can use a nested select to choose a subset of fields of relations to return. For example, the following query returns the user's name and the title of each related post:const user = await prisma.user.findFirst({ select: { name: true, ...
$queryRaw<User[]>`SELECT * FROM User`;// result is of type: `User[]`Note: If you do not provide a type, $queryRaw defaults to unknown.If you are selecting specific fields of the model or want to include relations, refer to the documentation about leveraging Prisma Client's generated...
When selecting specific fields on a toOne relation the extension will manually add the configured deleted field to the select object, filter the results and finally strip the deleted field from the results before returning them.For example the following query would behave that way:...
// All posts with ratings data const postsWithRatings = await prisma.post.findMany({ include: { // Here you can keep including data from other models ratings: true }, // you can also "select" specific properties }); // Calculate on your API const ratedPosts = postsWithRatings.map( ...
When selecting specific fields on a toOne relation the extension will manually add the configured deleted field to the select object, filter the results and finally strip the deleted field from the results before returning them.For example the following query would behave that way:...
select can be used to return specific fields, while omit can now be used to exclude specific fields. omit lives at the same API level and works on all of the same Prisma Client model queries as select. Note, however, that omit and select are mutually exclusive. In other words, you can...
// Explicitly select some fields (exclusive) const genres = await prisma.genres.findMany({ first: 10, select: { id: true, name: true } }) // Fetch all scalars and include first 10 tracks via relation const genresWithTracks = await prisma.genres.findMany({ ...
To improve the current API, we've added the possibility to retrieve scalar fields and (nested) relations in a type-safe way viaselectandincludearguments. Here is a sneak peek of what the API for field selection and fetching relations looks like: ...
quantity: { lte: prisma.product.fields.warnQuantity } }, }) To learn more about this feature, refer to ourdocumentation. Support for filtering non-unique columns in queries for a unique record We’re excited to announce theextendedWhereUniquePreview feature is now Generally Available. This means...
Result<typeof prisma.user, { select: { id: true } }, 'findFirstOrThrow'>async function main() { const user: ExtendedUser = await prisma.user.findFirstOrThrow({ select: { id: true, __typename: true, }, }) console.log(user.__typename) // Output: 'User'}main()...