class CommentaireGroupeGestionnaire < ApplicationRecord include Discard::Model belongs_to :groupe_gestionnaire belongs_to :gestionnaire, optional: true belongs_to :sender, polymorphic: true validates :body, presence: { message: "ne peut ĂȘtre vide" } def soft_deletable?(connected_user) sent_by?(connected_user) && sent_by_gestionnaire? && !discarded? end def soft_delete! discard! end def sent_by_gestionnaire? gestionnaire_id.present? end def sent_by?(someone) if gestionnaire someone == gestionnaire else someone == sender end end end