I have a simple Prisma schema from docs:
model Movie {
director Director @map(["directorFirstName", "directorLastName"])
title String
@@id([director, title])
}
model Director {
firstName String
lastName String
@@id([firstName, lastName])
}
When I do simple await prisma.movie.findMany() call, I receive only title property in the objects, even if the underlying query is fetching the id columns:

This behavior makes the object impossible to uniquely identify, which might be needed in plenty of use cases, like relations resolving in GraphQL resolvers, where we need all id columns to perform a findOne query:
await prisma.movie.findOne({
where: {
director_title: {
title: "Hello World",
director: {
directorFirstName: "Bob",
directorLastName: "Nolan",
},
},
},
});
It should always return all id columns and reflect that in typings - either by new properties:
/**
* Model Movie
*/
export type Movie = {
title: string
directorFirstName: string;
directorLastName: string;
}
Or by populating the properties aka auto-select:

I'm afraid there is no alternatives available because of lack of uniquness of the response data.
For generated resolvers we can always include the director keys but this results in additional query:
prisma:query SELECT `dev`.`Director`.`firstName`, `dev`.`Director`.`lastName` FROM `dev`.`Director` WHERE (`dev`.`Director`.`firstName`,`dev`.`Director`.`lastName`) IN (VALUES (?,?),(?,?)) LIMIT ? OFFSET ?
And still breaks custom queries/resolvers 馃槥
This will be most likely addressed through this issue: https://github.com/prisma/prisma2/issues/1606#issuecomment-601753275
Also related: https://github.com/prisma/prisma2/issues/829 and https://github.com/prisma/prisma-client-js/issues/188
This is implemented now and available on alpha.
Most helpful comment
This is implemented now and available on
alpha.