comment.rb 975 字节
Newer Older
1
class Comment < ActiveRecord::Base
2
  scope :limit_by, lambda {|l| limit(l) }
J
Jon Leighton 已提交
3 4 5 6
  scope :containing_the_letter_e, -> { where("comments.body LIKE '%e%'") }
  scope :not_again, -> { where("comments.body NOT LIKE '%again%'") }
  scope :for_first_post, -> { where(:post_id => 1) }
  scope :for_first_author, -> { joins(:post).where("posts.author_id" => 1) }
7
  scope :created, -> { all }
8

9
  belongs_to :post, :counter_cache => true
10
  has_many :ratings
J
Jeremy Kemper 已提交
11

12 13
  belongs_to :first_post, :foreign_key => :post_id

14 15 16
  has_many :children, :class_name => 'Comment', :foreign_key => :parent_id
  belongs_to :parent, :class_name => 'Comment', :counter_cache => :children_count

17 18 19
  def self.what_are_you
    'a comment...'
  end
J
Jeremy Kemper 已提交
20

21
  def self.search_by_type(q)
22
    where("#{QUOTED_TYPE} = ?", q)
23
  end
24 25 26 27

  def self.all_as_method
    all
  end
28
  scope :all_as_scope, -> { all }
29 30
end

31 32
class SpecialComment < Comment
end
33

34 35 36
class SubSpecialComment < SpecialComment
end

37
class VerySpecialComment < Comment
38
end