Update models, views, and fixtures for polymorphic reactions
- Reaction: belongs_to :reactable (polymorphic) instead of :comment - Comment: has_many :reactions with as: :reactable - Views: use reaction.reactable instead of reaction.comment - Fixtures: use polymorphic syntax for reactable association Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,7 @@ class Comment < ApplicationRecord
|
|||||||
belongs_to :account, default: -> { card.account }
|
belongs_to :account, default: -> { card.account }
|
||||||
belongs_to :card, touch: true
|
belongs_to :card, touch: true
|
||||||
belongs_to :creator, class_name: "User", default: -> { Current.user }
|
belongs_to :creator, class_name: "User", default: -> { Current.user }
|
||||||
has_many :reactions, -> { order(:created_at) }, dependent: :delete_all
|
has_many :reactions, -> { order(:created_at) }, as: :reactable, dependent: :delete_all
|
||||||
|
|
||||||
has_rich_text :body
|
has_rich_text :body
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class Reaction < ApplicationRecord
|
class Reaction < ApplicationRecord
|
||||||
belongs_to :account, default: -> { comment.account }
|
belongs_to :account, default: -> { reactable.account }
|
||||||
belongs_to :comment, touch: true
|
belongs_to :reactable, polymorphic: true, touch: true
|
||||||
belongs_to :reacter, class_name: "User", default: -> { Current.user }
|
belongs_to :reacter, class_name: "User", default: -> { Current.user }
|
||||||
|
|
||||||
scope :ordered, -> { order(:created_at) }
|
scope :ordered, -> { order(:created_at) }
|
||||||
@@ -11,6 +11,6 @@ class Reaction < ApplicationRecord
|
|||||||
|
|
||||||
private
|
private
|
||||||
def register_card_activity
|
def register_card_activity
|
||||||
comment.card.touch_last_active_at
|
reactable.card.touch_last_active_at
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
class: [ "txt-small", { "txt-medium": reaction.all_emoji? } ],
|
class: [ "txt-small", { "txt-medium": reaction.all_emoji? } ],
|
||||||
data: { action: "click->reaction-delete#reveal keydown.enter->reaction-delete#reveal:prevent", reaction_delete_target: "content" } %>
|
data: { action: "click->reaction-delete#reveal keydown.enter->reaction-delete#reveal:prevent", reaction_delete_target: "content" } %>
|
||||||
|
|
||||||
<%= button_to card_comment_reaction_path(reaction.comment.card, reaction.comment, reaction),
|
<%= button_to card_comment_reaction_path(reaction.reactable.card, reaction.reactable, reaction),
|
||||||
method: :delete,
|
method: :delete,
|
||||||
class: "reaction__delete btn btn--negative flex-item-justify-end",
|
class: "reaction__delete btn btn--negative flex-item-justify-end",
|
||||||
data: { action: "reaction-delete#perform", reaction_delete_target: "button" } do %>
|
data: { action: "reaction-delete#perform", reaction_delete_target: "button" } do %>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
json.cache! reaction do
|
json.cache! reaction do
|
||||||
json.(reaction, :id, :content)
|
json.(reaction, :id, :content)
|
||||||
json.reacter reaction.reacter, partial: "users/user", as: :user
|
json.reacter reaction.reacter, partial: "users/user", as: :user
|
||||||
json.url card_comment_reaction_url(reaction.comment.card, reaction.comment, reaction)
|
json.url card_comment_reaction_url(reaction.reactable.card, reaction.reactable, reaction)
|
||||||
end
|
end
|
||||||
|
|||||||
Vendored
+2
-2
@@ -2,12 +2,12 @@ kevin:
|
|||||||
id: <%= ActiveRecord::FixtureSet.identify("kevin_reaction", :uuid) %>
|
id: <%= ActiveRecord::FixtureSet.identify("kevin_reaction", :uuid) %>
|
||||||
account: 37s_uuid
|
account: 37s_uuid
|
||||||
content: "👍"
|
content: "👍"
|
||||||
comment: logo_agreement_jz_uuid
|
reactable: logo_agreement_jz_uuid (Comment)
|
||||||
reacter: kevin_uuid
|
reacter: kevin_uuid
|
||||||
|
|
||||||
david:
|
david:
|
||||||
id: <%= ActiveRecord::FixtureSet.identify("david_reaction", :uuid) %>
|
id: <%= ActiveRecord::FixtureSet.identify("david_reaction", :uuid) %>
|
||||||
account: 37s_uuid
|
account: 37s_uuid
|
||||||
content: "👍"
|
content: "👍"
|
||||||
comment: logo_agreement_jz_uuid
|
reactable: logo_agreement_jz_uuid (Comment)
|
||||||
reacter: david_uuid
|
reacter: david_uuid
|
||||||
|
|||||||
Reference in New Issue
Block a user