1 class Author < ActiveRecord::Base
3 has_many :posts_with_comments, :include => :comments, :class_name => "Post"
4 has_many :posts_with_categories, :include => :categories, :class_name => "Post"
5 has_many :posts_with_comments_and_categories, :include => [ :comments, :categories ], :order => "posts.id", :class_name => "Post"
6 has_many :posts_with_extension, :class_name => "Post" do #, :extend => ProxyTestExtension
7 def testing_proxy_owner
10 def testing_proxy_reflection
13 def testing_proxy_target
17 has_many :comments, :through => :posts
18 has_many :comments_desc, :through => :posts, :source => :comments, :order => 'comments.id DESC'
19 has_many :limited_comments, :through => :posts, :source => :comments, :limit => 1
20 has_many :funky_comments, :through => :posts, :source => :comments
22 has_many :special_posts
23 has_many :special_post_comments, :through => :special_posts, :source => :comments
25 has_many :special_nonexistant_posts, :class_name => "SpecialPost", :conditions => "posts.body = 'nonexistant'"
26 has_many :special_nonexistant_post_comments, :through => :special_nonexistant_posts, :source => :comments, :conditions => "comments.post_id = 0"
27 has_many :nonexistant_comments, :through => :posts
29 has_many :hello_posts, :class_name => "Post", :conditions => "posts.body = 'hello'"
30 has_many :hello_post_comments, :through => :hello_posts, :source => :comments
31 has_many :posts_with_no_comments, :class_name => 'Post', :conditions => 'comments.id is null', :include => :comments
33 has_many :other_posts, :class_name => "Post"
34 has_many :posts_with_callbacks, :class_name => "Post", :before_add => :log_before_adding,
35 :after_add => :log_after_adding,
36 :before_remove => :log_before_removing,
37 :after_remove => :log_after_removing
38 has_many :posts_with_proc_callbacks, :class_name => "Post",
39 :before_add => Proc.new {|o, r| o.post_log << "before_adding#{r.id || '<new>'}"},
40 :after_add => Proc.new {|o, r| o.post_log << "after_adding#{r.id || '<new>'}"},
41 :before_remove => Proc.new {|o, r| o.post_log << "before_removing#{r.id}"},
42 :after_remove => Proc.new {|o, r| o.post_log << "after_removing#{r.id}"}
43 has_many :posts_with_multiple_callbacks, :class_name => "Post",
44 :before_add => [:log_before_adding, Proc.new {|o, r| o.post_log << "before_adding_proc#{r.id || '<new>'}"}],
45 :after_add => [:log_after_adding, Proc.new {|o, r| o.post_log << "after_adding_proc#{r.id || '<new>'}"}]
46 has_many :unchangable_posts, :class_name => "Post", :before_add => :raise_exception, :after_add => :log_after_adding
48 has_many :categorizations
49 has_many :categories, :through => :categorizations
51 has_many :categories_like_general, :through => :categorizations, :source => :category, :class_name => 'Category', :conditions => { :name => 'General' }
53 has_many :categorized_posts, :through => :categorizations, :source => :post
54 has_many :unique_categorized_posts, :through => :categorizations, :source => :post, :uniq => true
56 has_many :nothings, :through => :kateggorisatons, :class_name => 'Category'
58 has_many :author_favorites
59 has_many :favorite_authors, :through => :author_favorites, :order => 'name'
61 has_many :tagging, :through => :posts # through polymorphic has_one
62 has_many :taggings, :through => :posts, :source => :taggings # through polymorphic has_many
63 has_many :tags, :through => :posts # through has_many :through
64 has_many :post_categories, :through => :posts, :source => :categories
66 belongs_to :author_address
68 attr_accessor :post_log
79 def log_before_adding(object)
80 @post_log << "before_adding#{object.id || '<new>'}"
83 def log_after_adding(object)
84 @post_log << "after_adding#{object.id}"
87 def log_before_removing(object)
88 @post_log << "before_removing#{object.id}"
91 def log_after_removing(object)
92 @post_log << "after_removing#{object.id}"
95 def raise_exception(object)
96 raise Exception.new("You can't add a post")
100 class AuthorAddress < ActiveRecord::Base
104 class AuthorFavorite < ActiveRecord::Base
106 belongs_to :favorite_author, :class_name => "Author", :foreign_key => 'favorite_author_id'