1 class Post
< ActiveRecord
::Base
2 named_scope
:containing_the_letter_a, :conditions => "body LIKE '%a%'"
3 named_scope
:with_authors_at_address, lambda
{ |address
| {
4 :conditions => [ 'authors.author_address_id = ?', address
.id
],
5 :joins => 'JOIN authors ON authors.id = posts.author_id'
15 belongs_to
:author_with_posts, :class_name => "Author", :foreign_key => :author_id, :include => :posts
16 belongs_to
:author_with_address, :class_name => "Author", :foreign_key => :author_id, :include => :author_address
18 has_one
:last_comment, :class_name => 'Comment', :order => 'id desc'
20 has_many
:comments, :order => "body" do
22 find(:first, :order => "id DESC")
26 has_many
:author_favorites, :through => :author
28 has_many
:comments_with_interpolated_conditions, :class_name => 'Comment',
29 :conditions => ['#{"#{aliased_table_name}." rescue ""}body = ?', 'Thank you for the welcome']
31 has_one
:very_special_comment
32 has_one
:very_special_comment_with_post, :class_name => "VerySpecialComment", :include => :post
33 has_many
:special_comments
34 has_many
:nonexistant_comments, :class_name => 'Comment', :conditions => 'comments.id < 0'
36 has_and_belongs_to_many
:categories
37 has_and_belongs_to_many
:special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id'
39 has_many
:taggings, :as => :taggable
40 has_many
:tags, :through => :taggings do
41 def add_joins_and_select
42 find
:all, :select => 'tags.*, authors.id as author_id', :include => false,
43 :joins => 'left outer join posts on taggings.taggable_id = posts.id left outer join authors on posts.author_id = authors.id'
47 has_many
:funky_tags, :through => :taggings, :source => :tag
48 has_many
:super_tags, :through => :taggings
49 has_one
:tagging, :as => :taggable
51 has_many
:invalid_taggings, :as => :taggable, :class_name => "Tagging", :conditions => 'taggings.id < 0'
52 has_many
:invalid_tags, :through => :invalid_taggings, :source => :tag
54 has_many
:categorizations, :foreign_key => :category_id
55 has_many
:authors, :through => :categorizations
58 has_many
:people, :through => :readers
59 has_many
:people_with_callbacks, :source=>:person, :through => :readers,
60 :before_add => lambda
{|owner
, reader
| log(:added, :before, reader
.first_name
) },
61 :after_add => lambda
{|owner
, reader
| log(:added, :after, reader
.first_name
) },
62 :before_remove => lambda
{|owner
, reader
| log(:removed, :before, reader
.first_name
) },
63 :after_remove => lambda
{|owner
, reader
| log(:removed, :after, reader
.first_name
) }
69 def self.log(message
=nil, side
=nil, new_record
=nil)
70 return @log if message
.nil?
71 @log << [message
, side
, new_record
]
79 class SpecialPost
< Post
; end
82 self.abstract_class
= true
83 has_one
:special_comment, :class_name => "SpecialComment"
86 class SubStiPost
< StiPost
87 self.table_name
= Post
.table_name