P
Prisma2mo ago
edarcode

self-relation

Greetings! Could someone help me? I haven't been able to understand this. I'm checking the followers and following of a user and everything appears correct in my db, but then when I check it the result is reversed. Any idea why? That 1 should appear in following and not in followers.
22 Replies
edarcode
edarcode2mo ago
No description
edarcode
edarcode2mo ago
No description
Nurul
Nurul2mo ago
Do you mean the value in followingId and followerId should be replaced? Can you please elaborate?
edarcode
edarcode2mo ago
No description
edarcode
edarcode2mo ago
Currently there are 2 users, the idea is that user A follows user B To represent this follow-up, there must be a table containing AId and BId, I named it Follow
edarcode
edarcode2mo ago
No description
edarcode
edarcode2mo ago
As you can see, A or followerId already follows B or followingId So when I check A and his followers it should return a 0, and his following should return a 1, but it comes out the other way around. And I'm very frustrated because I've already checked every possible error in detail and I don't see anything wrong T.T @Nurul (Prisma)
edarcode
edarcode2mo ago
final result is inverted
No description
edarcode
edarcode2mo ago
No description
edarcode
edarcode2mo ago
I have deleted package.lock, updated dependencies, asked many colleagues, etc. and I have not been able to find the error, I have checked my schema a thousand times, I am dead, I have asked chatGPT. I have read the doc I really don't want to leave Prisma, I like it a lot. And I don't see any alternatives either. So I don't know what to do.
Nurul
Nurul2mo ago
Can you share your schema.prisma file? Also, how are you inserting the record in Follow table?
edarcode
edarcode2mo ago
yes 1s
model User {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

followers Follow[] @relation("followers")
following Follow[] @relation("following")
}

model Follow {
followerId String
followingId String
createdAt DateTime @default(now())

follower User @relation("followers", fields: [followerId], references: [id])
following User @relation("following", fields: [followingId], references: [id])

@@id([followerId, followingId])
}
model User {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

followers Follow[] @relation("followers")
following Follow[] @relation("following")
}

model Follow {
followerId String
followingId String
createdAt DateTime @default(now())

follower User @relation("followers", fields: [followerId], references: [id])
following User @relation("following", fields: [followingId], references: [id])

@@id([followerId, followingId])
}
edarcode
edarcode2mo ago
No description
edarcode
edarcode2mo ago
@Nurul (Prisma)
Nurul
Nurul2mo ago
Let me create a minimal working example with your schema and share it with you
Want results from more Discord servers?
Add your server