comment.rb 1.0 KB
Newer Older
1
class Comment < ActiveRecord::Base
2
  scope :limit_by, lambda {|l| limit(l) }
J
Jon Leighton 已提交
3 4 5 6 7
  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) }
  scope :created, -> { scoped }
8

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

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

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

19
  def self.search_by_type(q)
20
    self.find(:all, :conditions => ["#{QUOTED_TYPE} = ?", q])
21
  end
22 23 24 25

  def self.all_as_method
    all
  end
J
Jon Leighton 已提交
26
  scope :all_as_scope, -> { scoped }
27 28
end

29
class SpecialComment < Comment
30 31 32
  def self.what_are_you
    'a special comment...'
  end
33
end
34

35 36 37
class SubSpecialComment < SpecialComment
end

38
class VerySpecialComment < Comment
39 40 41
  def self.what_are_you
    'a very special comment...'
  end
42
end