Froze rails gems
[depot.git] / vendor / rails / activerecord / test / models / post.rb
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'
6 }
7 }
8
9 belongs_to :author do
10 def greeting
11 "hello"
12 end
13 end
14
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
17
18 has_one :last_comment, :class_name => 'Comment', :order => 'id desc'
19
20 has_many :comments, :order => "body" do
21 def find_most_recent
22 find(:first, :order => "id DESC")
23 end
24 end
25
26 has_many :author_favorites, :through => :author
27
28 has_many :comments_with_interpolated_conditions, :class_name => 'Comment',
29 :conditions => ['#{"#{aliased_table_name}." rescue ""}body = ?', 'Thank you for the welcome']
30
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'
35
36 has_and_belongs_to_many :categories
37 has_and_belongs_to_many :special_categories, :join_table => "categories_posts", :association_foreign_key => 'category_id'
38
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'
44 end
45 end
46
47 has_many :funky_tags, :through => :taggings, :source => :tag
48 has_many :super_tags, :through => :taggings
49 has_one :tagging, :as => :taggable
50
51 has_many :invalid_taggings, :as => :taggable, :class_name => "Tagging", :conditions => 'taggings.id < 0'
52 has_many :invalid_tags, :through => :invalid_taggings, :source => :tag
53
54 has_many :categorizations, :foreign_key => :category_id
55 has_many :authors, :through => :categorizations
56
57 has_many :readers
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) }
64
65 def self.reset_log
66 @log = []
67 end
68
69 def self.log(message=nil, side=nil, new_record=nil)
70 return @log if message.nil?
71 @log << [message, side, new_record]
72 end
73
74 def self.what_are_you
75 'a post...'
76 end
77 end
78
79 class SpecialPost < Post; end
80
81 class StiPost < Post
82 self.abstract_class = true
83 has_one :special_comment, :class_name => "SpecialComment"
84 end
85
86 class SubStiPost < StiPost
87 self.table_name = Post.table_name
88 end