Slackbot
12/20/2021, 11:17 PMAnirudh Nimmagadda
12/21/2021, 12:39 PMconst usersWithCount = await prisma.user.findMany({
include: {
_count: {
select: { posts: {where: {approved: true}} },
},
},
})
Julien Goux
12/21/2021, 1:26 PMJulien Goux
12/21/2021, 1:28 PMNeo Lambada
12/21/2021, 2:48 PMmodel User {
id Int @id @default(autoincrement())
method User_method
name String @db.VarChar(255)
email String @unique(map: "email") @db.VarChar(255)
createdAt DateTime @default(now()) @db.DateTime(0)
updatedAt DateTime @default(now()) @db.DateTime(0)
//relationships
shops Shop[]
ShoppingCart ShoppingCart[]
followedBy FollowUser[] @relation("follower")
following FollowUser[] @relation("following")
}
model FollowUser {
status Boolean @default(false)
createdAt DateTime @default(now()) @db.DateTime(0)
updatedAt DateTime @default(now()) @db.DateTime(0)
//relationShips
follower User @relation("follower", fields: [followerId], references: [id])
following User @relation("following", fields: [followingId], references: [id])
followerId Int @unique
followingId Int @unique
}
Neo Lambada
12/21/2021, 2:49 PMNeo Lambada
12/21/2021, 2:49 PMconst followedUser = await context.prisma.followUser.upsert({
where: { followerId: 4, followingId: args.userId },
update: { status: args.status },
})
Neo Lambada
12/21/2021, 2:50 PMTyler Strout
12/21/2021, 3:09 PMkyle travelet
12/21/2021, 4:35 PMarnu515
12/21/2021, 5:11 PMmembers
property, but it is just returning all organisations, even the ones the user isn't part of.
Here's the code I'm using to query, and here's my schema.prisma
.arnu515
12/21/2021, 5:12 PMarnu515
12/21/2021, 5:12 PMJoshua Ramin
12/21/2021, 7:27 PMChris Packett
12/21/2021, 8:00 PMasync getByCallbackUuid(callbackUuid: string, includeAccount = false) {
if (includeAccount) {
const queryIncludeAccount =
await prismaClient.webhookSubscription.findUnique({
where: {
callbackUuid,
},
include: {
account: true,
},
});
return queryIncludeAccount;
}
const queryExcludeAccount =
await prismaClient.webhookSubscription.findUnique({
where: {
callbackUuid,
},
});
return queryExcludeAccount;
}
Chris Packett
12/21/2021, 8:01 PMincludeAccount
is false, the return type would be inferred as Promise<WebhookSubscription | null>
; and when includeAccount
is true, the return type would be inferred as (WebhookSubscription & { account: Account; }) | null
.Anton Pokhylenko
12/21/2021, 8:25 PM"generate:prisma": "./node_modules/.bin/prisma generate"
also tried using prisma generate
but got same error
my dependencies have "@prisma/client": "3.2.0",
and devDependencies have "prisma": "3.2.0"
locally everything works fine
does anyone know what could potentially change in this regard?Vasily Zorin
12/21/2021, 10:05 PMChip Clark
12/21/2021, 10:26 PMERROR [ExceptionsHandler] Cannot read property '$executeRawUnsafe' of undefined
code:
async deletePersonRelationship(where: Prisma.PersonRelationshipWhereUniqueInput) {
const insert = `DELETE FROM [dbo].[PersonRelationship] WHERE PersonRelationshipID=${where.PersonRelationshipID};`;
return this.prisma.$executeRawUnsafe(insert);
// return this.prisma.$executeRaw`DELETE FROM [dbo].[PersonRelationship] WHERE PersonRelationshipID=${where.PersonRelationshipID};`;
// the above line doesn't work either
}
where:
{ PersonRelationshipID: 359 }
If I run the script on the SQL server, it works.
Similar issue with Update and Create.
With Update I tried using the internal Prisma commands:
async updatePersonRelationship(params: {
where: Prisma.PersonRelationshipWhereUniqueInput;
data: Prisma.PersonRelationshipUpdateInput;
}) {
const { data, where } = params;
const response = await this.prisma.personRelationship.update({
data,
where,
});
}
but I get the following error:
ERROR [ExceptionsHandler] Cannot read property 'personRelationship' of undefined
If I switch to the following code:
async updatePersonRelationship(params: {
where: Prisma.PersonRelationshipWhereUniqueInput;
data: Prisma.PersonRelationshipUpdateInput;
}) {
const { data, where } = params;
console.log('\n\n\n' + JSON.stringify(data) + '\n\n\n');
// const response = await this.prisma.personRelationship.update({
// data,
// where,
// });
// console.log(response);
const insert = `UPDATE [dbo].[PersonRelationship]
SET ActiveFromDate=$data.ActiveFromDate,
ModifiedBy=$ModifiedBy,
PKPersonID=$PKPersonID,
RelatedPersonID=$RelatedPersonID,
RelationshipTypeID=$RelationshipTypeID
WHERE PersonRelationshipID=$where`;
return this.prisma.$executeRawUnsafe(insert);
}
I get the following error:
{"ActiveFromDate":"2021-12-21T00:00:00.000Z","ModifiedBy":"MDD Admin Tool","PKPersonID":18,"RelatedPerson":285,"RelationshipTypeID":1}
[Nest] 102196 - 12/21/2021, 2:22:32 PM ERROR [ExceptionsHandler] Cannot read property '$executeRawUnsafe' of undefined
I included the console log of the data to show what was passed.
Again, this script works on the sql server.
I am at a loss as to why I'm getting undefined errors.Vasily Zorin
12/21/2021, 10:38 PMthis.prisma
is not defineduser
12/22/2021, 8:46 AMPedia of Sunnah
12/22/2021, 9:20 AMfindMany
export const docs = () => {
return db.doc.findMany()
}
schema:
model Doc {
id Int @id @default(autoincrement())
docable_type String
docable_id Int
file String
created_by Int
updated_by Int
deleted_at DateTime?
created_at DateTime? @default(now())
updated_at DateTime? @updatedAt
title String?
tenant Tenant? @relation(fields: [tenant_id], references: [id])
tenant_id Int?
@@map("docs")
}
Have a solution for this?Pedia of Sunnah
12/22/2021, 9:21 AMhj yuiyui
12/22/2021, 10:28 AMmodel groupevent{
groupevent_id Int @id @default(autoincrement())
website_id Int
created_at DateTime? @default(now()) @db.Timestamptz(6)
event_type String @db.VarChar(50)
event_value String @db.VarChar(50)
website website @relation(fields: [website_id], references: [website_id])
event event?
}
and this query to create a new record
export async function createEvent(website_id, event_type, event_value) {
return runQuery(
prisma.groupevent.create({
data : {
website:{connect: {website_id: website_id}},
event_type: event_type?.substr(0, 50),
event_value: event_value?.substr(0, 50),
}
})
)
}
and this is my post route if (req.method === 'POST') {
if (!(await allowQuery(req))) {
return unauthorized(res);
}
const { id, event_type, event_value } = req.query;
const websiteId = +id;
const events = await createEvent(websiteId,event_value, event_type);
return ok(res, events);
}
and this how i call my post route on my front end const onSubmit = (dataForm: IFormValues) => {
const idStr: string = idWebsite.toString();
const data = {
id: idWebsite,
event_type : dataForm.event_type,
event_value: dataForm.event_value
};
const url: string = window.apiUrl;
`post(${url}/api/website/${idStr}/events
, data)(didnt paste the following, its useless)` and when i try to post i get this PRISMA error on my server log Argument event_type for data.event_type is missing.
Argument event_value for data.event_value is missing.
Any idea why ?George Lewis
12/22/2021, 11:00 AMmodel OrganizationMembership {
id String @id @default(cuid())
permissions OrganizationPermission[]
dailyVerseNotification Boolean? @default(false)
organization Organization @relation(fields: [organizationId], references: [id])
organizationId String
profile Profile? @relation(fields: [profileId], references: [id])
profileId String?
user User? @relation(fields: [userId], references: [id])
userId String?
startDate DateTime @default(now())
updatedAt DateTime @updatedAt
meetingRoomReservationModerated MeetingRoomReservation[]
@@unique([userId, organizationId])
// @@index([profileId])
// @@index([userId])
// @@index([organizationId])
// @@unique([profileId, organizationId])
}
and a resolver to query all the organizationMemberships as follow
async organizationMemberships(
_parent: any,
args: OrganizationMembershipsArgs,
ctx: ContextInterface
): Promise<OrganizationMembership[]> {
const organizationMemberships = ctx.prisma.organizationMembership.findMany({
where: {
id: args.where?.id,
userId: args.where?.user?.id,
organizationId: args.where?.organizationId?.length
? { in: args.where.organizationId }
: undefined,
user: {
profile: {
name_search_key: {
contains: args.where?.name_search_key,
mode: 'insensitive'
}
}
}
},
skip: args.skip,
take: args.first
})
The problem is that when i run the query (Searching by OrganizationId) I only get the records that have a user entity not the rest (with null user). can anyone help?Dimitri Ivashchuk
12/22/2021, 12:30 PMaggregate relations
but I am still struggling to make it work/find the docs. Is it really implemented or still in progress?Victor Tr
12/22/2021, 2:12 PMmodel User {
id String @id @default(uuid())
Squads UserSquadMap[] // I would like this to be an implicit maping of the actual mapped Squad. => Squad[]
OwnedSquads Squad[]
}
model Squad {
id String
owner_id String
Owner User @relation(fields: [owner_id], references: [id], onDelete: NoAction, onUpdate: NoAction)
Members UserSquadMap[] // And this obviously => Users[]
}
// The Join Table
model UserSquadMap {
userId String
squadId String
User User @relation(fields: [userId], references: [id], onDelete: Cascade)
Squad Squad @relation(fields: [squadId], references: [id], onDelete: Cascade)
@@id([userId, squadId])
@@index([squadId])
@@index([userId])
}
I want to directly reference the JoinTable relation entity so that I don't have nested includes {}
and nested responses with irrelevant data. Right now I'm just transforming the object in the actual response, but surely there's a better way to directly reference it somehow? Is this possible? (I have been looking at @@map
but no no avail, yet)Mateus Silva
12/22/2021, 2:36 PMprismaMock
but it's not workinghj yuiyui
12/22/2021, 3:34 PMFelix Wohnhaas
12/22/2021, 3:50 PMprisma db pull
. This worked, however my schema now contains all sorts of mappings to existing keys, constraints, …
E.g.:
@id(map: "PK_71a8d4792f7790deb531235496c")
@relation(fields: [seasonId], references: [id], onDelete: Cascade, onUpdate: NoAction, map: "FK_2725433beb670562c7ffe20b5a2")
These mapped IDs do not exist in the production database. My question is: Can I safely remove these mappings? What are they used / needed for? When starting “fresh”, prisma also does not generate these mappings..