diff --git a/apps/ritgram/backend/prisma/schema.prisma b/apps/ritgram/backend/prisma/schema.prisma index 5f5bdf7e..b562c215 100644 --- a/apps/ritgram/backend/prisma/schema.prisma +++ b/apps/ritgram/backend/prisma/schema.prisma @@ -58,8 +58,20 @@ model Account { comments Comment[] likes Like[] - followers Follow[] @relation("AccountFollowers") - following Follow[] @relation("AccountFollowing") + // NOTE (2026-11-18, follower/following count-swap fix): these two back-relation + // field *names* were swapped relative to what they actually return. Follow's + // own `follower`/`following` scalar fields (below) are correctly named -- + // `follower` is the Account referenced by `followerId` (the one doing the + // following), `following` is the Account referenced by `followingId` (the + // one being followed). But the list field tagged "AccountFollowers" is the + // back-relation for `followerId`, i.e. every Follow row where *this* Account + // is the follower -- that's "accounts I follow", not "accounts following me". + // Swapping just these two labels (no relation-name/FK/column change, no + // migration) makes `following` mean "who I follow" and `followers` mean + // "who follows me", matching every reader (_count.select.followers/following + // etc.) across the backend. See plans/railyard.md, 2026-11-18 entry. + following Follow[] @relation("AccountFollowers") + followers Follow[] @relation("AccountFollowing") sentMessages Message[] @relation("MessageSender") receivedMessages Message[] @relation("MessageReceiver") @@ -138,8 +150,15 @@ model User { storyHighlights StoryHighlight[] // Social - followers Follow[] @relation("UserFollowers") - following Follow[] @relation("UserFollowing") + // Same count-swap fix as Account above (2026-11-18): field *names* swapped, + // relation tags/FKs untouched, no migration needed. `following` is now the + // back-relation for "UserFollowers" (Follow rows where this user is + // followerUserId, i.e. users this one follows); `followers` is now the + // back-relation for "UserFollowing" (Follow rows where this user is + // followingUserId, i.e. users following this one). See followService.ts + // and plans/railyard.md, 2026-11-18 entry, for the rest of this story. + following Follow[] @relation("UserFollowers") + followers Follow[] @relation("UserFollowing") sessions Session[] subscription Subscription?