aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/models/author.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2008-01-19 05:30:42 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2008-01-19 05:30:42 +0000
commit16b129a68ca1770815107a3edb54090282349ba7 (patch)
treefedc506d08a766066a829ae8efa3d691cc719aff /activerecord/test/models/author.rb
parentf95ff8d4dc37ced3b4493ad628e3ff7e5d950efd (diff)
downloadrails-16b129a68ca1770815107a3edb54090282349ba7.tar.gz
rails-16b129a68ca1770815107a3edb54090282349ba7.tar.bz2
rails-16b129a68ca1770815107a3edb54090282349ba7.zip
belongs_to supports :dependent => :destroy and :delete. Closes #10592.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8675 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/models/author.rb')
-rw-r--r--activerecord/test/models/author.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/test/models/author.rb b/activerecord/test/models/author.rb
index bf0c993c50..593d77342e 100644
--- a/activerecord/test/models/author.rb
+++ b/activerecord/test/models/author.rb
@@ -65,7 +65,8 @@ class Author < ActiveRecord::Base
has_many :tags, :through => :posts # through has_many :through
has_many :post_categories, :through => :posts, :source => :categories
- belongs_to :author_address
+ belongs_to :author_address, :dependent => :destroy
+ belongs_to :author_address_extra, :dependent => :delete, :class_name => "AuthorAddress"
attr_accessor :post_log
@@ -101,6 +102,17 @@ end
class AuthorAddress < ActiveRecord::Base
has_one :author
+
+ def self.destroyed_author_address_ids
+ @destroyed_author_address_ids ||= Hash.new { |h,k| h[k] = [] }
+ end
+
+ before_destroy do |author_address|
+ if author_address.author
+ AuthorAddress.destroyed_author_address_ids[author_address.author.id] << author_address.id
+ end
+ true
+ end
end
class AuthorFavorite < ActiveRecord::Base