diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2006-08-29 17:06:27 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2006-08-29 17:06:27 +0000 |
commit | 3704088ebde5ef074d186bff0d380858a9a01055 (patch) | |
tree | cae788b86554be381aff084f7b3da48a4fc428b4 /activerecord/test/fixtures/company.rb | |
parent | 92f1e26a1c9f48ac575414976012d6dfa127bdac (diff) | |
download | rails-3704088ebde5ef074d186bff0d380858a9a01055.tar.gz rails-3704088ebde5ef074d186bff0d380858a9a01055.tar.bz2 rails-3704088ebde5ef074d186bff0d380858a9a01055.zip |
has_one supports the :dependent => :delete option which skips the typical callback chain and deletes the associated object directly from the database. Closes #5927.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4848 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/fixtures/company.rb')
-rwxr-xr-x | activerecord/test/fixtures/company.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/fixtures/company.rb b/activerecord/test/fixtures/company.rb index 250deebb21..a55632360f 100755 --- a/activerecord/test/fixtures/company.rb +++ b/activerecord/test/fixtures/company.rb @@ -42,6 +42,9 @@ class DependentFirm < Company has_many :companies, :foreign_key => 'client_of', :order => "id", :dependent => :nullify end +class ExclusivelyDependentFirm < Company + has_one :account, :foreign_key => "firm_id", :dependent => :delete +end class Client < Company belongs_to :firm, :foreign_key => "client_of" @@ -83,6 +86,18 @@ end class Account < ActiveRecord::Base belongs_to :firm + def self.destroyed_account_ids + @destroyed_account_ids ||= Hash.new { |h,k| h[k] = [] } + end + + before_destroy do |account| + if account.firm + Account.destroyed_account_ids[account.firm.id] << account.id + end + true + end + + protected def validate errors.add_on_empty "credit_limit" |