Matt
04/18/2020, 12:02 AMreturn ctx.prisma.lead
.findOne({
where: args,
include: {
User: true,
LeadCampaign: { include: { LeadSource: true } },
},
})
It successfully pulls the right row from the lead table and also the associated row from the associated LeadCampaign table and the correct row for the LeadSource that's associated with it.
However, when I try to get a list of leads with their associated data like so:
return ctx.prisma.lead
.findMany({
where: args,
include: {
User: true,
LeadCampaign: { include: { LeadSource: true } },
},
})
I get the error: Expected at most 1 item for 'LeadSource', got 21
I found in the documentation that "_The only requirement for chaining is that the previous function call must return only a single object (e.g. as returned by a findOne
query or a "to-one relation" like profile.user()
)._" So I get that it can't pull a list of items from a parent that was also a list, but each lead has only one LeadCampaign and each LeadCampaign only has one LeadSource, so it seems like it's meeting the "to-one relation" part of that statement. Do I need to write it differently? Or do I need to write a function to pull different queries and stitch the results together myself?