Ethan Pursley
04/15/2020, 11:59 PMCharlie Meaden
04/16/2020, 12:04 AMCharlie Meaden
04/16/2020, 12:04 AMCharlie Meaden
04/16/2020, 12:05 AMEthan Pursley
04/16/2020, 12:06 AMCharlie Meaden
04/16/2020, 12:07 AMEthan Pursley
04/16/2020, 12:07 AMEthan Pursley
04/16/2020, 12:07 AMCharlie Meaden
04/16/2020, 12:08 AMEthan Pursley
04/16/2020, 12:15 AMAlexZp
04/16/2020, 11:14 AMenum Permission {
ADMIN
USER
ITEMCREATE
ITEMUPDATE
ITEMDELETE
PERMISSIONUPDATE
}
type User {
id: ID! @id
name: String!
email: String! @unique
password: String!
resetToken: String
resetTokenExpiry: Float
createdAt: DateTime! @createdAt
updatedAt: DateTime! @updatedAt
permissions: [Permission!]! @scalarList(strategy: RELATION)
}
and then I create a mutation with query ctx.db.query.user({ where: { email } });
but get return without permissions
field. "message": "Cannot return null for non-nullable field User.permissions."
On prisma.io server, User have this field with a set valuesdy
04/16/2020, 1:38 PMdek sch
04/16/2020, 1:42 PMKJReactor
04/16/2020, 2:43 PMAlexZp
04/16/2020, 3:43 PMAlan
04/17/2020, 4:08 AMLog
. What would be the Prisma architecture to have 2 distincts databases (`User`/`Post` and Log
)Daan Helsloot
04/17/2020, 8:05 AMstephan
04/17/2020, 8:24 AMChad H
04/17/2020, 11:02 AMJames Homer
04/17/2020, 6:01 PMMatt
04/17/2020, 6:26 PM...
return ctx.prisma.TableA
.findMany({
where: {
...
},
include: {
TableBconnectionField: true },
})
...
I get all the fields in Table A and all the fields in Table B.
But I also have a connection field in Table B to Table C and I need some data from that included in the return JSON as well. If I put
...
return ctx.prisma.TableA
.findMany({
where: {
...
},
include: {
TableBconnectionField: {
select: { field_1: true, field_2: true, TableCconnectionField: true },
}
},
})
...
I get all the fields for Tables A and C but only get field_1 and field_2 for Table B. Is there a way to do this that gives me all the fields for Table B as well without me having to explicitly request them?Alp Karavil
04/17/2020, 6:46 PMapp.get(`/projects/:id`, async (req, res) => {
const { id } = req.params;
const project = await prisma.project.findOne({
where: {
id: Number(id),
},
});
const resourcesOfProject = await prisma.project
.findOne({ where: { id: Number(id) } })
.resources();
res.status(200).json({ ...project, resources: resourcesOfProject });
});
// Here is some of my schema
model Resource {
id Int @default(autoincrement()) @id
name String
description String?
projects Project[] @relation(references: [id])
}
model Project {
id Int @default(autoincrement()) @id
name String
description String?
tasks Task[]
resources Resource[] @relation(references: [id])
completed Boolean @default(false)
}
Adriano Resende
04/17/2020, 10:20 PMAdriano Resende
04/17/2020, 10:21 PMBrendan Dolan
04/17/2020, 10:46 PMBrendan Dolan
04/17/2020, 11:55 PMVince Biro
04/17/2020, 11:56 PMMatt
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?Aman Chaudhary
04/18/2020, 7:21 AMomnyx2
04/18/2020, 1:50 PM