2005-04-03 10:52:05 +00:00
|
|
|
class Author < ActiveRecord::Base
|
2005-04-03 17:50:11 +00:00
|
|
|
has_many :posts
|
2005-11-06 20:39:34 +00:00
|
|
|
has_many :posts_with_comments, :include => :comments, :class_name => "Post"
|
|
|
|
has_many :posts_with_categories, :include => :categories, :class_name => "Post"
|
2005-11-08 04:36:37 +00:00
|
|
|
has_many :posts_with_comments_and_categories, :include => [ :comments, :categories ], :order => "posts.id", :class_name => "Post"
|
2006-03-19 02:01:40 +00:00
|
|
|
has_many :comments, :through => :posts
|
2006-03-19 07:14:48 +00:00
|
|
|
has_many :funky_comments, :through => :posts, :class_name => 'Comment'
|
2005-11-06 20:39:34 +00:00
|
|
|
|
2006-03-18 23:14:31 +00:00
|
|
|
has_many :special_posts, :class_name => "Post"
|
|
|
|
has_many :hello_posts, :class_name => "Post", :conditions=>"\#{aliased_table_name}.body = 'hello'"
|
|
|
|
has_many :nonexistent_posts, :class_name => "Post", :conditions=>"\#{aliased_table_name}.body = 'nonexistent'"
|
2005-07-04 08:43:57 +00:00
|
|
|
has_many :posts_with_callbacks, :class_name => "Post", :before_add => :log_before_adding,
|
2006-03-18 23:14:31 +00:00
|
|
|
:after_add => :log_after_adding,
|
|
|
|
:before_remove => :log_before_removing,
|
|
|
|
:after_remove => :log_after_removing
|
2005-11-08 04:36:37 +00:00
|
|
|
has_many :posts_with_proc_callbacks, :class_name => "Post",
|
2006-03-18 23:14:31 +00:00
|
|
|
:before_add => Proc.new {|o, r| o.post_log << "before_adding#{r.id}"},
|
|
|
|
:after_add => Proc.new {|o, r| o.post_log << "after_adding#{r.id}"},
|
2005-11-08 04:36:37 +00:00
|
|
|
:before_remove => Proc.new {|o, r| o.post_log << "before_removing#{r.id}"},
|
2006-03-18 23:14:31 +00:00
|
|
|
:after_remove => Proc.new {|o, r| o.post_log << "after_removing#{r.id}"}
|
2005-11-08 04:36:37 +00:00
|
|
|
has_many :posts_with_multiple_callbacks, :class_name => "Post",
|
2005-07-04 08:43:57 +00:00
|
|
|
:before_add => [:log_before_adding, Proc.new {|o, r| o.post_log << "before_adding_proc#{r.id}"}],
|
2006-03-18 23:14:31 +00:00
|
|
|
:after_add => [:log_after_adding, Proc.new {|o, r| o.post_log << "after_adding_proc#{r.id}"}]
|
2005-07-04 08:43:57 +00:00
|
|
|
has_many :unchangable_posts, :class_name => "Post", :before_add => :raise_exception, :after_add => :log_after_adding
|
|
|
|
|
2005-12-11 18:06:51 +00:00
|
|
|
has_many :categorizations
|
|
|
|
has_many :categories, :through => :categorizations
|
2006-03-21 01:07:16 +00:00
|
|
|
|
2006-03-18 03:39:18 +00:00
|
|
|
has_many :nothings, :through => :kateggorisatons, :class_name => 'Category'
|
2005-12-11 18:06:51 +00:00
|
|
|
|
2006-03-21 01:07:16 +00:00
|
|
|
has_many :author_favorites
|
|
|
|
has_many :favorite_authors, :through => :author_favorites, :order => 'name'
|
|
|
|
|
2006-03-19 19:32:07 +00:00
|
|
|
belongs_to :author_address
|
|
|
|
|
2005-07-04 08:43:57 +00:00
|
|
|
attr_accessor :post_log
|
|
|
|
|
|
|
|
def after_initialize
|
2005-11-08 04:36:37 +00:00
|
|
|
@post_log = []
|
2005-07-04 08:43:57 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2005-11-08 04:36:37 +00:00
|
|
|
def log_before_adding(object)
|
|
|
|
@post_log << "before_adding#{object.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_after_adding(object)
|
|
|
|
@post_log << "after_adding#{object.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_before_removing(object)
|
|
|
|
@post_log << "before_removing#{object.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def log_after_removing(object)
|
|
|
|
@post_log << "after_removing#{object.id}"
|
|
|
|
end
|
|
|
|
|
|
|
|
def raise_exception(object)
|
|
|
|
raise Exception.new("You can't add a post")
|
|
|
|
end
|
|
|
|
end
|
2006-03-19 19:32:07 +00:00
|
|
|
|
|
|
|
class AuthorAddress < ActiveRecord::Base
|
|
|
|
has_one :author
|
2006-03-21 01:07:16 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
class AuthorFavorite < ActiveRecord::Base
|
|
|
|
belongs_to :author
|
|
|
|
belongs_to :favorite_author, :class_name => "Author", :foreign_key => 'favorite_author_id'
|
2006-03-19 19:32:07 +00:00
|
|
|
end
|