374e536a5b9fb80f041667986cf485b6d1080e09
1 class Post
< ActiveRecord
::Base
2 named_scope
:containing_the_letter_a, :conditions => "body LIKE '%a%'"
3 named_scope
:ranked_by_comments, :order => "comments_count DESC"
4 named_scope
:limit, lambda
{|limit
| {:limit => limit
} }
5 named_scope
:with_authors_at_address, lambda
{ |address
| {
6 :conditions => [ 'authors.author_address_id = ?', address
.id
],
7 :joins => 'JOIN authors ON authors.id = posts.author_id'
17 belongs_to
:author_with_posts, :class_name => "Author", :foreign_key => :author_id, :include => :posts
18 belongs_to
:author_with_address, :class_name => "Author", :foreign_key => :author_id, :include => :author_address
20 has_one
:last_comment, :class_name => 'Comment', :order => 'id desc'
22 named_scope
:with_special_comments, :joins => :comments, :conditions => {:comments => {:type => 'SpecialComment'} }
23 named_scope
:with_very_special_comments, :joins => :comments, :conditions => {:comments => {:type => 'VerySpecialComment'} }
24 named_scope
:with_post, lambda
{|post_id
|
25 { :joins => :comments, :conditions => {:comments => {:post_id => post_id
} } }
28 has_many
:comments, :order => "body" do
30 find(:first, :order => "id DESC")
34 has_many
:author_favorites, :through => :author
36 has_many
:comments_with_interpolated_conditions, :class_name => 'Comment',
37 :conditions => ['#{"#{aliased_table_name}." rescue ""}body = ?', 'Thank you for the welcome']
39 has_one
:very_special_comment
40 has_one
:very_special_comment_with_post, :class_name => "VerySpecialComment", :include => :post
41 has_many
:special_comments
42 has_many
:nonexistant_comments, :class_name => 'Comment', :conditions => 'comments.id < 0'
44 has_and_belongs_to_many
:categories
45 has_and_belongs_to_many
:special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id'
47 has_many
:taggings, :as => :taggable
48 has_many
:tags, :through => :taggings do
49 def add_joins_and_select
50 find
:all, :select => 'tags.*, authors.id as author_id', :include => false,
51 :joins => 'left outer join posts on taggings.taggable_id = posts.id left outer join authors on posts.author_id = authors.id'
55 has_many
:funky_tags, :through => :taggings, :source => :tag
56 has_many
:super_tags, :through => :taggings
57 has_one
:tagging, :as => :taggable
59 has_many
:invalid_taggings, :as => :taggable, :class_name => "Tagging", :conditions => 'taggings.id < 0'
60 has_many
:invalid_tags, :through => :invalid_taggings, :source => :tag
62 has_many
:categorizations, :foreign_key => :category_id
63 has_many
:authors, :through => :categorizations
66 has_many
:people, :through => :readers
67 has_many
:people_with_callbacks, :source=>:person, :through => :readers,
68 :before_add => lambda
{|owner
, reader
| log(:added, :before, reader
.first_name
) },
69 :after_add => lambda
{|owner
, reader
| log(:added, :after, reader
.first_name
) },
70 :before_remove => lambda
{|owner
, reader
| log(:removed, :before, reader
.first_name
) },
71 :after_remove => lambda
{|owner
, reader
| log(:removed, :after, reader
.first_name
) }
74 ranked_by_comments
.limit(limit
)
81 def self.log(message
=nil, side
=nil, new_record
=nil)
82 return @log if message
.nil?
83 @log << [message
, side
, new_record
]
91 class SpecialPost
< Post
; end
94 self.abstract_class
= true
95 has_one
:special_comment, :class_name => "SpecialComment"
98 class SubStiPost
< StiPost
99 self.table_name
= Post
.table_name