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 | |
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')
-rw-r--r-- | activerecord/test/fixtures/accounts.yml | 7 | ||||
-rw-r--r-- | activerecord/test/fixtures/companies.yml | 7 | ||||
-rwxr-xr-x | activerecord/test/fixtures/company.rb | 15 |
3 files changed, 27 insertions, 2 deletions
diff --git a/activerecord/test/fixtures/accounts.yml b/activerecord/test/fixtures/accounts.yml index a3d6742d79..b2d0191900 100644 --- a/activerecord/test/fixtures/accounts.yml +++ b/activerecord/test/fixtures/accounts.yml @@ -20,4 +20,9 @@ last_account: rails_core_account_2: id: 5 firm_id: 6 - credit_limit: 55
\ No newline at end of file + credit_limit: 55 + +odegy_account: + id: 6 + firm_id: 9 + credit_limit: 53 diff --git a/activerecord/test/fixtures/companies.yml b/activerecord/test/fixtures/companies.yml index f2e638d382..c61128c09b 100644 --- a/activerecord/test/fixtures/companies.yml +++ b/activerecord/test/fixtures/companies.yml @@ -47,4 +47,9 @@ leetsoft: jadedpixel: id: 8 name: Jadedpixel - client_of: 6
\ No newline at end of file + client_of: 6 + +odegy: + id: 9 + name: Odegy + type: ExclusivelyDependentFirm 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" |