-
Notifications
You must be signed in to change notification settings - Fork 346
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use poly assoc for task comments
- Loading branch information
Showing
9 changed files
with
31 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
class AssessmentComment < TaskComment | ||
belongs_to :overseer_assessment, optional: false | ||
|
||
before_create do | ||
self.content_type = :assessment | ||
end | ||
|
||
def serialize(user) | ||
json = super(user) | ||
json[:overseer_assessment_id] = self.overseer_assessment_id | ||
json[:overseer_assessment_id] = self.commentable_id | ||
json | ||
end | ||
end |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
16 changes: 16 additions & 0 deletions
16
db/migrate/20240601103707_add_polymorphic_association_to_comment.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
class AddPolymorphicAssociationToComment < ActiveRecord::Migration[7.1] | ||
def change | ||
remove_index :task_comments, :overseer_assessment_id | ||
|
||
add_column :task_comments, :commentable_type, :string | ||
rename_column :task_comments, :overseer_assessment_id, :commentable_id | ||
|
||
TaskComment.find_each do |comment| | ||
if comment.commentable_id.present? | ||
comment.update(commentable_type: 'OverseerAssessment') | ||
end | ||
end | ||
|
||
add_index :task_comments, [:commentable_type, :commentable_id] | ||
end | ||
end |
7 changes: 0 additions & 7 deletions
7
db/migrate/20240601103707_add_test_attempt_link_to_comment.rb
This file was deleted.
Oops, something went wrong.
This file contains 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
This file contains 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