P
Prisma•3d ago
Rami kadaweh

default data using prisma

const specialities = await this.prisma.speciality.findMany({ include: { specialityLabel: { where: { language: 'fr'}} } }) i want if specific speciality does not have record specialityLabel with language 'fr' to let it got the record with language : 'en' as default
2 Replies
Nurul
Nurul•3d ago
Hello @Rami kadaweh 👋 Is your goal to achieve this in a single prisma query? You can check the number of records returned by the speciality query, and if no records are returned then you can query for language: 'en'
const specialities = await this.prisma.speciality.findMany({
include: {
specialityLabel: { where: { language: 'fr'}}
}
})

if(specialities.length === 0){
const enSpecialities = this.prisma.speciality.findMany({
include: {
specialityLabel: { where: { language: 'en'}}
}
})
}
const specialities = await this.prisma.speciality.findMany({
include: {
specialityLabel: { where: { language: 'fr'}}
}
})

if(specialities.length === 0){
const enSpecialities = this.prisma.speciality.findMany({
include: {
specialityLabel: { where: { language: 'en'}}
}
})
}
Nurul
Nurul•3d ago
You can also create considering a client extension similar to this one: https://github.com/prisma/prisma-client-extensions/tree/main/input-transformation
GitHub
prisma-client-extensions/input-transformation at main · prisma/pris...
Examples of Prisma Client extensions. Contribute to prisma/prisma-client-extensions development by creating an account on GitHub.
Want results from more Discord servers?
Add your server