Files
fizzy/app/models/comment.rb
T
Mike Dalessio 79c9ea2ce1 Remove a bunch of N+1s
related to notification and comment rendering
2025-11-27 11:08:45 -05:00

29 lines
875 B
Ruby

class Comment < ApplicationRecord
include Attachments, Eventable, Mentions, Promptable, Searchable
belongs_to :account, default: -> { card.account }
belongs_to :card, touch: true
belongs_to :creator, class_name: "User", default: -> { Current.user }
has_many :reactions, -> { order(:created_at) }, dependent: :delete_all
has_rich_text :body
scope :chronologically, -> { order created_at: :asc, id: :desc }
scope :preloaded, -> { with_rich_text_body.includes(reactions: :reacter) }
scope :by_system, -> { joins(:creator).where(creator: { role: "system" }) }
scope :by_user, -> { joins(:creator).where.not(creator: { role: "system" }) }
after_create_commit :watch_card_by_creator
delegate :board, :watch_by, to: :card
def to_partial_path
"cards/#{super}"
end
private
def watch_card_by_creator
card.watch_by creator
end
end