diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2008-01-19 05:30:42 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2008-01-19 05:30:42 +0000 |
commit | 16b129a68ca1770815107a3edb54090282349ba7 (patch) | |
tree | fedc506d08a766066a829ae8efa3d691cc719aff /activerecord/test/models | |
parent | f95ff8d4dc37ced3b4493ad628e3ff7e5d950efd (diff) | |
download | rails-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')
-rw-r--r-- | activerecord/test/models/author.rb | 14 |
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 |