diff options
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" |