comment.rb 716 字节
Newer Older
1
class Comment < ActiveRecord::Base
2
  scope :limit_by, lambda {|l| limit(l) }
P
Pratik Naik 已提交
3 4 5
  scope :containing_the_letter_e, :conditions => "comments.body LIKE '%e%'"
  scope :for_first_post, :conditions => { :post_id => 1 }
  scope :for_first_author,
6 7 8
              :joins => :post,
              :conditions => { "posts.author_id" => 1 }

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

11 12 13
  def self.what_are_you
    'a comment...'
  end
J
Jeremy Kemper 已提交
14

15
  def self.search_by_type(q)
16
    self.find(:all, :conditions => ["#{QUOTED_TYPE} = ?", q])
17
  end
18 19
end

20
class SpecialComment < Comment
21 22 23
  def self.what_are_you
    'a special comment...'
  end
24
end
25

26
class VerySpecialComment < Comment
27 28 29
  def self.what_are_you
    'a very special comment...'
  end
30
end