]> git.openstreetmap.org Git - rails.git/blob - app/models/note_comment.rb
Merge remote-tracking branch 'upstream/pull/2267'
[rails.git] / app / models / note_comment.rb
1 # == Schema Information
2 #
3 # Table name: note_comments
4 #
5 #  id         :bigint(8)        not null, primary key
6 #  note_id    :bigint(8)        not null
7 #  visible    :boolean          not null
8 #  created_at :datetime         not null
9 #  author_ip  :inet
10 #  author_id  :bigint(8)
11 #  body       :text
12 #  event      :enum
13 #
14 # Indexes
15 #
16 #  index_note_comments_on_body        (to_tsvector('english'::regconfig, body)) USING gin
17 #  index_note_comments_on_created_at  (created_at)
18 #  note_comments_note_id_idx          (note_id)
19 #
20 # Foreign Keys
21 #
22 #  note_comments_author_id_fkey  (author_id => users.id)
23 #  note_comments_note_id_fkey    (note_id => notes.id)
24 #
25
26 class NoteComment < ActiveRecord::Base
27   belongs_to :note, :foreign_key => :note_id, :touch => true
28   belongs_to :author, :class_name => "User", :foreign_key => :author_id
29
30   validates :id, :uniqueness => true, :presence => { :on => :update },
31                  :numericality => { :on => :update, :integer_only => true }
32   validates :note, :presence => true, :associated => true
33   validates :visible, :inclusion => [true, false]
34   validates :author, :associated => true
35   validates :event, :inclusion => %w[opened closed reopened commented hidden]
36   validates :body, :length => { :maximum => 2000 }, :characters => true
37
38   # Return the comment text
39   def body
40     RichText.new("text", self[:body])
41   end
42 end