Eric Martinez
06/05/2021, 3:18 PMSELECT p.codigo, f.sumaPctPagado, b.id, b2.comentario
FROM proyecto p
LEFT JOIN (
SELECT sum(porc_hes) as sumaPctPagado, id_pry
FROM facturacion
GROUP BY id_pry
) f
ON p.codigo = f.id_pry
LEFT JOIN (
SELECT max(id) as id, id_pry
FROM bitacora
GROUP BY id_pry
) b
ON p.codigo = b.id_pry
LEFT JOIN bitacora b2
ON b.id = b2.id
I tried this
await prisma.proyecto.aggregate({
_sum: {
include: {
facturacion: {
porc_hes: true
}
}
}
});
And it's not possible, it failed immediatly. Should I "modularize" (move them out of the main query) the nested queries? I see that as an alternative but I haven't tried it yet.David Ilizarov
06/06/2021, 5:32 AMmodel User {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
chats Chat[]
}
model Chat {
id Int @id @default(autoincrement())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
private Boolean? @default(false)
users User[]
}
I want to find the chat that includes specific users, but I don't want it including other users and it MUST include all users in my array - like if you want a chat with users [1,2,3]
(not just [1,2]
and definitely not [1,2,3,4]
)... this is the best I got.
this.prisma.chat.findFirst({
where: {
users: {
every: {
OR: [{id: 1}, {id: 2}, {id: 3}]
}
}
}
})
The problem with the above is that it matches chats for users [1,2]
... Feels like I might be forced to do a chat.findMany
and then post-query processing.
In an ideal world I'd be able to do something like include the count of users I want and then If I include a count of 3, that that coupled with the every OR clause should sufficiently find me my channel.
Is that possible? Thoughts?Daniel Esteves
06/06/2021, 6:07 AMlinks Link[]
but that also can be of type Link[]
or type Embed[]
, is there a way?Roblox Studio
06/06/2021, 7:53 AMLevi Lawliet
06/06/2021, 12:14 PMJohn
06/06/2021, 2:26 PMJohn
06/06/2021, 2:26 PMJohn
06/06/2021, 2:26 PMJohn
06/06/2021, 2:27 PMEric Martinez
06/06/2021, 2:30 PMpreviewFeatures = ["selectRelationCount"]
in your schema file?Ruslan Gonzalez
06/06/2021, 4:32 PMRuslan Gonzalez
06/06/2021, 4:36 PMRuslan Gonzalez
06/06/2021, 4:37 PMDan Shapir
06/06/2021, 6:29 PMWilliam Stanley
06/06/2021, 8:24 PMdb.set.create({
data: {
...someData,
tokens: {
createMany: { // <-- need upsert equiv here
data: [...tokens]
}
}
}
})
Danil Kolesnikov
06/07/2021, 1:28 AMsome
and every
with a more complex use-case for filtering on relations. Is this a bug with Prisma or I am not using it correctly?
Goal: Given an organization id, provide all forms associated with it.
Reality: when using every
clause the filtering doesn't work as expected, we get all forms from all organization. When using some
, we get forms from only that organization (expected).
Code:
prisma.applicationFormConfig.findMany({
where: { organizations: { every: { id: organization.id } } },
})// yield all forms from all organization
prisma.applicationFormConfig.findMany({
where: { organizations: { some: { id: organization.id } } },
}),// works as expected
Why? Please help.
More context:
After inspecting SQL, it becomes obvious why, this is raw query for `every`:
prisma:query SELECT "public"."ApplicationFormConfig"."id", ... FROM "public"."ApplicationFormConfig" WHERE ("public"."ApplicationFormConfig"."id")
NOT IN (SELECT "t0"."A" FROM "public"."_ApplicationFormConfigToOrganization" AS "t0"
INNER JOIN "public"."Organization" AS "j0" ON ("j0"."id") = ("t0"."B")
WHERE ((NOT "j0"."id" = $1) AND "t0"."A" IS NOT NULL)) OFFSET $2
look at WHERE ((NOT "j0"."id" = $1)
which will yield all other records. $1
is the organization.id
in the prisma query.
When using some
, it is fixed:
WHERE ("j0"."id" = $1
Schema:
model ApplicationFormConfig {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
...
organizations Organization[]
}
model Organization {
id String @id @default(dbgenerated("gen_random_uuid()")) @db.Uuid
...
applicationFormConfigs ApplicationFormConfig[]
...
}
Ruslan Gonzalez
06/07/2021, 10:25 AMRuslan Gonzalez
06/07/2021, 10:25 AMuser
06/07/2021, 11:17 AMuser
06/07/2021, 11:26 AMNatalia
Levi Lawliet
06/07/2021, 4:12 PMjuanloco
06/07/2021, 4:24 PMnpx prisma db seed --preview-feature
from the heroku console. The command seemed to run, and then process exited but there is still no data in the DB. I have run this locally and it has worked perfectly fine.Levi Lawliet
06/07/2021, 5:02 PMAND
operation. I have a schema graphql schema like thisDan Shapir
06/07/2021, 5:47 PMpx prisma migrate dev --name initial-migration --create-only
but npx prisma db push
returns all is synced. even did and introspect. I don’t have any migrations, I worked only with db push until now.Dan Shapir
06/07/2021, 5:59 PMGiorgio Delgado
06/07/2021, 6:32 PMON DELETE CASCADE
trigger set up on my foreign key reference … where can I see that in mysql
? I tried looking inside the information_schema.triggers
table and didn’t find anything 😕Giorgio Delgado
06/07/2021, 6:34 PMON DELETE
or ON UPDATE
triggers that I have on my database?Giorgio Delgado
06/07/2021, 6:34 PMmysql
Giorgio Delgado
06/07/2021, 6:39 PM