1 # frozen_string_literal: true
 
   3 # == Schema Information
 
   5 # Table name: note_comments
 
   7 #  id         :bigint           not null, primary key
 
   8 #  note_id    :bigint           not null
 
   9 #  visible    :boolean          not null
 
  10 #  created_at :datetime         not null
 
  18 #  index_note_comments_on_author_id_and_created_at  (author_id,created_at)
 
  19 #  index_note_comments_on_body                      (to_tsvector('english'::regconfig, body)) USING gin
 
  20 #  index_note_comments_on_created_at                (created_at)
 
  21 #  note_comments_note_id_idx                        (note_id)
 
  25 #  note_comments_author_id_fkey  (author_id => users.id)
 
  26 #  note_comments_note_id_fkey    (note_id => notes.id)
 
  29 class NoteComment < ApplicationRecord
 
  30   belongs_to :note, :touch => true
 
  31   belongs_to :author, :class_name => "User", :optional => true, :counter_cache => true
 
  33   validates :id, :uniqueness => true, :presence => { :on => :update },
 
  34                  :numericality => { :on => :update, :only_integer => true }
 
  35   validates :note, :associated => true
 
  36   validates :visible, :inclusion => [true, false]
 
  37   validates :author, :associated => true
 
  38   validates :event, :inclusion => %w[opened closed reopened commented hidden]
 
  39   validates :body, :length => { :maximum => 2000 }, :characters => true
 
  41   # Return the comment text
 
  43     RichText.new("text", self[:body])