2005-04-03 06:52:05 -04:00
|
|
|
class Comment < ActiveRecord::Base
|
2011-04-17 15:47:52 -04:00
|
|
|
scope :limit_by, lambda {|l| limit(l) }
|
2012-03-21 18:18:18 -04:00
|
|
|
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) }
|
2012-07-27 12:27:47 -04:00
|
|
|
scope :created, -> { all }
|
2011-07-11 19:04:01 -04:00
|
|
|
|
2008-01-26 01:23:03 -05:00
|
|
|
belongs_to :post, :counter_cache => true
|
2014-04-23 22:51:00 -04:00
|
|
|
belongs_to :author, polymorphic: true
|
|
|
|
belongs_to :resource, polymorphic: true
|
2014-07-14 20:25:18 -04:00
|
|
|
belongs_to :developer
|
2014-04-23 22:51:00 -04:00
|
|
|
|
2010-10-09 17:00:33 -04:00
|
|
|
has_many :ratings
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2012-04-03 15:13:24 -04:00
|
|
|
belongs_to :first_post, :foreign_key => :post_id
|
|
|
|
|
2011-07-11 19:04:01 -04:00
|
|
|
has_many :children, :class_name => 'Comment', :foreign_key => :parent_id
|
|
|
|
belongs_to :parent, :class_name => 'Comment', :counter_cache => :children_count
|
|
|
|
|
2005-07-22 16:05:42 -04:00
|
|
|
def self.what_are_you
|
|
|
|
'a comment...'
|
|
|
|
end
|
2008-01-18 02:27:03 -05:00
|
|
|
|
2005-07-22 16:05:42 -04:00
|
|
|
def self.search_by_type(q)
|
2012-07-27 12:27:47 -04:00
|
|
|
where("#{QUOTED_TYPE} = ?", q)
|
2005-07-22 16:05:42 -04:00
|
|
|
end
|
2011-01-02 15:33:18 -05:00
|
|
|
|
|
|
|
def self.all_as_method
|
|
|
|
all
|
|
|
|
end
|
2012-07-27 12:27:47 -04:00
|
|
|
scope :all_as_scope, -> { all }
|
2014-05-05 03:48:59 -04:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
body
|
|
|
|
end
|
2005-04-10 11:49:49 -04:00
|
|
|
end
|
|
|
|
|
2005-11-04 14:39:50 -05:00
|
|
|
class SpecialComment < Comment
|
|
|
|
end
|
2005-07-22 16:05:42 -04:00
|
|
|
|
2010-10-06 07:06:51 -04:00
|
|
|
class SubSpecialComment < SpecialComment
|
|
|
|
end
|
|
|
|
|
2005-11-04 14:39:50 -05:00
|
|
|
class VerySpecialComment < Comment
|
2008-01-26 01:23:03 -05:00
|
|
|
end
|
2014-05-12 17:30:05 -04:00
|
|
|
|
|
|
|
class CommentThatAutomaticallyAltersPostBody < Comment
|
|
|
|
belongs_to :post, class_name: "PostThatLoadsCommentsInAnAfterSaveHook", foreign_key: :post_id
|
2014-05-14 19:29:30 -04:00
|
|
|
|
2014-05-12 17:30:05 -04:00
|
|
|
after_save do |comment|
|
|
|
|
comment.post.update_attributes(body: "Automatically altered")
|
|
|
|
end
|
2014-05-14 19:29:30 -04:00
|
|
|
end
|
2014-08-31 15:18:02 -04:00
|
|
|
|
|
|
|
class CommentWithDefaultScopeReferencesAssociation < Comment
|
|
|
|
default_scope ->{ includes(:developer).order('developers.name').references(:developer) }
|
|
|
|
belongs_to :developer
|
|
|
|
end
|