2005-04-03 10:52:05 +00:00
|
|
|
class Post < ActiveRecord::Base
|
2008-03-24 02:50:02 +00:00
|
|
|
named_scope :containing_the_letter_a, :conditions => "body LIKE '%a%'"
|
|
|
|
|
2005-11-06 19:05:42 +00:00
|
|
|
belongs_to :author do
|
2005-11-03 09:06:42 +00:00
|
|
|
def greeting
|
|
|
|
"hello"
|
|
|
|
end
|
2005-11-06 19:05:42 +00:00
|
|
|
end
|
2005-11-03 09:06:42 +00:00
|
|
|
|
2006-09-15 07:02:05 +00:00
|
|
|
belongs_to :author_with_posts, :class_name => "Author", :foreign_key => :author_id, :include => :posts
|
2005-11-06 20:39:34 +00:00
|
|
|
|
2005-11-06 19:05:42 +00:00
|
|
|
has_many :comments, :order => "body" do
|
2005-11-03 09:06:42 +00:00
|
|
|
def find_most_recent
|
|
|
|
find(:first, :order => "id DESC")
|
|
|
|
end
|
2005-11-06 19:05:42 +00:00
|
|
|
end
|
2005-11-03 09:06:42 +00:00
|
|
|
|
2008-01-19 04:19:53 +00:00
|
|
|
has_many :comments_with_interpolated_conditions, :class_name => 'Comment',
|
|
|
|
:conditions => ['#{"#{aliased_table_name}." rescue ""}body = ?', 'Thank you for the welcome']
|
|
|
|
|
2005-11-04 19:39:50 +00:00
|
|
|
has_one :very_special_comment
|
2005-11-06 20:39:34 +00:00
|
|
|
has_one :very_special_comment_with_post, :class_name => "VerySpecialComment", :include => :post
|
2005-11-04 19:39:50 +00:00
|
|
|
has_many :special_comments
|
2007-11-11 01:03:43 +00:00
|
|
|
has_many :nonexistant_comments, :class_name => 'Comment', :conditions => 'comments.id < 0'
|
2005-11-03 09:06:42 +00:00
|
|
|
|
2005-04-10 17:24:56 +00:00
|
|
|
has_and_belongs_to_many :categories
|
2006-03-16 02:10:11 +00:00
|
|
|
has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id'
|
2005-12-02 06:03:43 +00:00
|
|
|
|
|
|
|
has_many :taggings, :as => :taggable
|
2008-02-18 00:14:54 +00:00
|
|
|
has_many :tags, :through => :taggings do
|
2006-03-21 16:33:22 +00:00
|
|
|
def add_joins_and_select
|
|
|
|
find :all, :select => 'tags.*, authors.id as author_id', :include => false,
|
|
|
|
:joins => 'left outer join posts on taggings.taggable_id = posts.id left outer join authors on posts.author_id = authors.id'
|
|
|
|
end
|
|
|
|
end
|
2008-01-18 07:27:03 +00:00
|
|
|
|
2006-03-24 14:46:17 +00:00
|
|
|
has_many :funky_tags, :through => :taggings, :source => :tag
|
2006-03-18 22:38:49 +00:00
|
|
|
has_many :super_tags, :through => :taggings
|
2006-02-09 19:37:05 +00:00
|
|
|
has_one :tagging, :as => :taggable
|
|
|
|
|
2006-03-18 23:14:31 +00:00
|
|
|
has_many :invalid_taggings, :as => :taggable, :class_name => "Tagging", :conditions => 'taggings.id < 0'
|
2006-03-24 14:46:17 +00:00
|
|
|
has_many :invalid_tags, :through => :invalid_taggings, :source => :tag
|
2006-03-18 23:14:31 +00:00
|
|
|
|
2006-01-21 23:40:20 +00:00
|
|
|
has_many :categorizations, :foreign_key => :category_id
|
|
|
|
has_many :authors, :through => :categorizations
|
|
|
|
|
2006-02-10 05:19:41 +00:00
|
|
|
has_many :readers
|
|
|
|
has_many :people, :through => :readers
|
2008-04-06 00:27:12 +00:00
|
|
|
has_many :people_with_callbacks, :source=>:person, :through => :readers,
|
|
|
|
:before_add => lambda {|owner, reader| log(:added, :before, reader.first_name) },
|
|
|
|
:after_add => lambda {|owner, reader| log(:added, :after, reader.first_name) },
|
|
|
|
:before_remove => lambda {|owner, reader| log(:removed, :before, reader.first_name) },
|
|
|
|
:after_remove => lambda {|owner, reader| log(:removed, :after, reader.first_name) }
|
|
|
|
|
|
|
|
def self.reset_log
|
|
|
|
@log = []
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.log(message=nil, side=nil, new_record=nil)
|
|
|
|
return @log if message.nil?
|
|
|
|
@log << [message, side, new_record]
|
|
|
|
end
|
2006-02-10 05:19:41 +00:00
|
|
|
|
2005-07-22 20:05:42 +00:00
|
|
|
def self.what_are_you
|
|
|
|
'a post...'
|
|
|
|
end
|
2005-04-10 15:49:49 +00:00
|
|
|
end
|
|
|
|
|
2006-12-01 21:24:47 +00:00
|
|
|
class SpecialPost < Post; end
|
2005-07-03 08:21:22 +00:00
|
|
|
|
|
|
|
class StiPost < Post
|
2006-03-16 02:46:01 +00:00
|
|
|
self.abstract_class = true
|
2005-07-03 08:21:22 +00:00
|
|
|
has_one :special_comment, :class_name => "SpecialComment"
|
|
|
|
end
|
2006-03-16 02:46:01 +00:00
|
|
|
|
|
|
|
class SubStiPost < StiPost
|
2006-12-01 21:24:47 +00:00
|
|
|
self.table_name = Post.table_name
|
2006-03-16 02:46:01 +00:00
|
|
|
end
|