2005-04-03 06:52:05 -04:00
|
|
|
class Post < ActiveRecord::Base
|
2008-03-23 22:50:02 -04:00
|
|
|
named_scope :containing_the_letter_a, :conditions => "body LIKE '%a%'"
|
2008-06-21 07:41:30 -04:00
|
|
|
named_scope :with_authors_at_address, lambda { |address| {
|
|
|
|
:conditions => [ 'authors.author_address_id = ?', address.id ],
|
|
|
|
:joins => 'JOIN authors ON authors.id = posts.author_id'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-11-06 14:05:42 -05:00
|
|
|
belongs_to :author do
|
2005-11-03 04:06:42 -05:00
|
|
|
def greeting
|
|
|
|
"hello"
|
|
|
|
end
|
2005-11-06 14:05:42 -05:00
|
|
|
end
|
2005-11-03 04:06:42 -05:00
|
|
|
|
2006-09-15 03:02:05 -04:00
|
|
|
belongs_to :author_with_posts, :class_name => "Author", :foreign_key => :author_id, :include => :posts
|
2008-09-26 23:28:21 -04:00
|
|
|
belongs_to :author_with_address, :class_name => "Author", :foreign_key => :author_id, :include => :author_address
|
2005-11-06 15:39:34 -05:00
|
|
|
|
2008-05-01 19:00:42 -04:00
|
|
|
has_one :last_comment, :class_name => 'Comment', :order => 'id desc'
|
|
|
|
|
2005-11-06 14:05:42 -05:00
|
|
|
has_many :comments, :order => "body" do
|
2005-11-03 04:06:42 -05:00
|
|
|
def find_most_recent
|
|
|
|
find(:first, :order => "id DESC")
|
|
|
|
end
|
2005-11-06 14:05:42 -05:00
|
|
|
end
|
2005-11-03 04:06:42 -05:00
|
|
|
|
2008-10-04 10:42:36 -04:00
|
|
|
has_many :author_favorites, :through => :author
|
|
|
|
|
2008-01-18 23:19:53 -05:00
|
|
|
has_many :comments_with_interpolated_conditions, :class_name => 'Comment',
|
|
|
|
:conditions => ['#{"#{aliased_table_name}." rescue ""}body = ?', 'Thank you for the welcome']
|
|
|
|
|
2005-11-04 14:39:50 -05:00
|
|
|
has_one :very_special_comment
|
2005-11-06 15:39:34 -05:00
|
|
|
has_one :very_special_comment_with_post, :class_name => "VerySpecialComment", :include => :post
|
2005-11-04 14:39:50 -05:00
|
|
|
has_many :special_comments
|
2007-11-10 20:03:43 -05:00
|
|
|
has_many :nonexistant_comments, :class_name => 'Comment', :conditions => 'comments.id < 0'
|
2005-11-03 04:06:42 -05:00
|
|
|
|
2005-04-10 13:24:56 -04:00
|
|
|
has_and_belongs_to_many :categories
|
2006-03-15 21:10:11 -05:00
|
|
|
has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id'
|
2005-12-02 01:03:43 -05:00
|
|
|
|
|
|
|
has_many :taggings, :as => :taggable
|
2008-02-17 19:14:54 -05:00
|
|
|
has_many :tags, :through => :taggings do
|
2006-03-21 11:33:22 -05: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 02:27:03 -05:00
|
|
|
|
2006-03-24 09:46:17 -05:00
|
|
|
has_many :funky_tags, :through => :taggings, :source => :tag
|
2006-03-18 17:38:49 -05:00
|
|
|
has_many :super_tags, :through => :taggings
|
2006-02-09 14:37:05 -05:00
|
|
|
has_one :tagging, :as => :taggable
|
|
|
|
|
2006-03-18 18:14:31 -05:00
|
|
|
has_many :invalid_taggings, :as => :taggable, :class_name => "Tagging", :conditions => 'taggings.id < 0'
|
2006-03-24 09:46:17 -05:00
|
|
|
has_many :invalid_tags, :through => :invalid_taggings, :source => :tag
|
2006-03-18 18:14:31 -05:00
|
|
|
|
2006-01-21 18:40:20 -05:00
|
|
|
has_many :categorizations, :foreign_key => :category_id
|
|
|
|
has_many :authors, :through => :categorizations
|
|
|
|
|
2006-02-10 00:19:41 -05:00
|
|
|
has_many :readers
|
|
|
|
has_many :people, :through => :readers
|
2008-04-05 20:27:12 -04: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 00:19:41 -05:00
|
|
|
|
2005-07-22 16:05:42 -04:00
|
|
|
def self.what_are_you
|
|
|
|
'a post...'
|
|
|
|
end
|
2005-04-10 11:49:49 -04:00
|
|
|
end
|
|
|
|
|
2006-12-01 16:24:47 -05:00
|
|
|
class SpecialPost < Post; end
|
2005-07-03 04:21:22 -04:00
|
|
|
|
|
|
|
class StiPost < Post
|
2006-03-15 21:46:01 -05:00
|
|
|
self.abstract_class = true
|
2005-07-03 04:21:22 -04:00
|
|
|
has_one :special_comment, :class_name => "SpecialComment"
|
|
|
|
end
|
2006-03-15 21:46:01 -05:00
|
|
|
|
|
|
|
class SubStiPost < StiPost
|
2006-12-01 16:24:47 -05:00
|
|
|
self.table_name = Post.table_name
|
2006-03-15 21:46:01 -05:00
|
|
|
end
|