You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
class Comment < ApplicationRecord
belongs_to :commentable, polymorphic: true
end
class Document < ApplicationRecord
has_many :comments, as: :commentable
end
class Case < ApplicationRecord
has_many :comments, as: :commentable
end
class Service < ApplicationRecord
has_many :comments, as: :commentable
end
class Topic < ApplicationRecord
has_many :comments, as: :commentable
end
class Point < ApplicationRecord
has_many :comments, as: :commentable
end
Each comment would be stored with a "type" property, which would indicate whether it was a comment for a point, case, service, document, topic, etc.
The hard part would be figuring out what to do with existing comments. On the plus side, we could knock five controllers down to a single controller, and do away with a number of views.
This discussion was converted from issue #827 on January 28, 2021 00:03.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
We have five different tables in the database that seem to do the exact same thing. I think they need to be united under one table via a type of polymorphic association: https://guides.rubyonrails.org/association_basics.html#polymorphic-associations
It would work like this:
class Comment < ApplicationRecord
belongs_to :commentable, polymorphic: true
end
class Document < ApplicationRecord
has_many :comments, as: :commentable
end
class Case < ApplicationRecord
has_many :comments, as: :commentable
end
class Service < ApplicationRecord
has_many :comments, as: :commentable
end
class Topic < ApplicationRecord
has_many :comments, as: :commentable
end
class Point < ApplicationRecord
has_many :comments, as: :commentable
end
Each comment would be stored with a "type" property, which would indicate whether it was a comment for a point, case, service, document, topic, etc.
The hard part would be figuring out what to do with existing comments. On the plus side, we could knock five controllers down to a single controller, and do away with a number of views.
Beta Was this translation helpful? Give feedback.
All reactions