refactor: drop type Author from comments table#83
Merged
Conversation
Owner
Author
|
I propose replacing the struct fields api response - resolves to - |
Owner
Author
|
After the design changes were made there is no need to define the Preload field on comments' Author that was done previously. This also showed a hidden logic, that for fetching comments we needed the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
References #80 #85
Design issues -
the comment struct holds
to allow authors of types (faculty, warden and centrehead) to comment we need to change the struct design.
Claude documentation of the PR -
PR #83 — refactor: drop type Author from comments table
Branch:
fix/post-author→mainMerged: Jun 7, 2026
Label:
refactorReferences: #80, #85
Problem
The
Commentstruct held a hard-typedAuthor Adminassociation field:This restricted comment authorship to only
Adminusers. Faculty, Warden, and CentreHead users could not comment on their own posts since they are not of typeAdmin.Design Decision
Replaced
AuthorIDandAuthor Adminfields with flatemailandrolestring fields stored directly on the comment at insert time.Before:
{ "id": 1, "author_id": 1, "Author": { "id": 1, "email": "xen.civil@nith.ac.in", "password": "", "position": "XEN_Civil", "is_verified": false, "created_at": "0001-01-01T00:00:00Z" } }After:
{ "id": 1, "email": "xen.civil@nith.ac.in", "role": "XEN_Civil", "comment_text": "Inspection scheduled.", "created_at": "2026-05-28T13:53:08.190581+05:30" }Changes
models/comment.goAuthorID uintandAuthor AdminfieldsAuthorEmail stringandAuthorRole stringstored at insert timePreload("Author")on comment querieshandlers/— comment handlersAdminPostComment,FacultyPostComment,WardenPostComment,CentreHeadPostComment) to populateAuthorEmailandAuthorRolefrom the logged-in user at insert timefeat: add warden and centrehead post comment handlers)routes/handlers/admin_post.goAdminGetPostnow returns a server-driven response instead of raw model dumpSide Effect Discovered
Removing the
Preload("Author")on comments revealed thatCommentableTypeandCommentableIDare the actual fields GORM uses internally to resolve polymorphic associations — these were previously being implicitly resolved via the nested.SelectonAuthor.Commits
e7a09304054f96bd2a147403bc8e3c0eb0ec770c6c8ae5f3d39d4f8765534f6357ffbbWhy This Approach
password,is_verified