diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-09-28 03:52:57 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-09-28 03:52:57 +0000 |
commit | efaf2af07c4238e911899988871e575d8ef5805b (patch) | |
tree | a70ca8cfb227cb6aa47ac68fea84641fc4bab28d /activerecord/test/fixtures | |
parent | 1e87d6e887639650e23db5fbba0ccdf0536f289c (diff) | |
download | rails-efaf2af07c4238e911899988871e575d8ef5805b.tar.gz rails-efaf2af07c4238e911899988871e575d8ef5805b.tar.bz2 rails-efaf2af07c4238e911899988871e575d8ef5805b.zip |
r3653@asus: jeremy | 2005-09-28 00:23:49 -0700
Ticket 2221 - model.association.clear should destroy associated objects if :dependent => true instead of nullifying their foreign keys
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2384 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/test/fixtures')
-rwxr-xr-x | activerecord/test/fixtures/company.rb | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/activerecord/test/fixtures/company.rb b/activerecord/test/fixtures/company.rb index 5af39c1297..748d43eb2e 100755 --- a/activerecord/test/fixtures/company.rb +++ b/activerecord/test/fixtures/company.rb @@ -10,6 +10,8 @@ class Firm < Company has_many :clients, :order => "id", :dependent => true, :counter_sql => "SELECT COUNT(*) FROM companies WHERE firm_id = 1 AND (type = 'Client' OR type = 'SpecialClient' OR type = 'VerySpecialClient' )" has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC" has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id" + has_many :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => true + has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :exclusively_dependent => true has_many :clients_like_ms, :conditions => "name = 'Microsoft'", :class_name => "Client", :order => "id" has_many :clients_using_sql, :class_name => "Client", :finder_sql => 'SELECT * FROM companies WHERE client_of = #{id}' has_many :clients_using_counter_sql, :class_name => "Client", @@ -30,6 +32,20 @@ class Client < Company belongs_to :firm_with_basic_id, :class_name => "Firm", :foreign_key => "firm_id" belongs_to :firm_with_other_name, :class_name => "Firm", :foreign_key => "client_of" belongs_to :firm_with_condition, :class_name => "Firm", :foreign_key => "client_of", :conditions => "1 = 1" + + # Record destruction so we can test whether firm.clients.clear has + # is calling client.destroy, deleting from the database, or setting + # foreign keys to NULL. + def self.destroyed_client_ids + @destroyed_client_ids ||= Hash.new { |h,k| h[k] = [] } + end + + before_destroy do |client| + if client.firm + Client.destroyed_client_ids[client.firm.id] << client.id + end + true + end end |