fix(ritgram): correct swapped follower/following back-relation field names

Account.followers/following and User.followers/following were labeled
backwards relative to what they actually return: the "followers" field
on each model was the back-relation for the FK column that makes *this*
row the follower (i.e. "who I follow"), and "following" was the
back-relation for the FK column that makes this row the target (i.e.
"who follows me") -- exactly inverted from their names.

Swap just the two field names on each model (relation tags, FK columns,
and the Follow model's own follower/following fields are untouched, so
this needs zero DB migration). This fixes every _count.select.followers/
following read across router.ts, social.ts, resolvers.ts, adminController,
searchController, popularController, socialGraphService,
trendingRankingService, fakeAccountDetectionService, etc. in one place --
all profile header counts, followers/following list pages, and REST/
tRPC/GraphQL responses were pulling the inverted number.

followService.ts and the tRPC getFollowers/getFollowing procedures
already bypass these relations (query Follow directly by followerUserId/
followingUserId), so they were already correct and are unaffected.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
caelum0x 2026-11-18 02:41:24 +03:00
parent 74dc01549f
commit af2c2fcd04

View File

@ -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?