diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 94af33d777237a53d14296c7f30edb6101a1fd6f..4218174442bdba53163d2bf14d98c2ef90cec145 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -271,7 +271,7 @@ module ClassMethods # * collection=objects - replaces the collections content by deleting and adding objects as appropriate. # * collection_singular_ids=ids - replace the collection by the objects identified by the primary keys in +ids+ # * collection.clear - removes every object from the collection. This destroys the associated objects if they - # are :dependent, deletes them directly from the database if they are :exclusively_dependent, + # are :dependent, deletes them directly from the database if they are :dependent => :delete_all, # and sets their foreign keys to NULL otherwise. # * collection.empty? - returns true if there are no associated objects. # * collection.size - returns the number of associated objects. diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb index a66248ff2e0ae3a7150ae7c7d25beb3e27757968..8e249d1b943e9c4479108ff5925cf57da4952468 100644 --- a/activerecord/lib/active_record/associations/association_collection.rb +++ b/activerecord/lib/active_record/associations/association_collection.rb @@ -62,7 +62,7 @@ def delete(*records) def clear return self if length.zero? # forces load_target if hasn't happened already - if @reflection.options[:exclusively_dependent] + if @reflection.options[:dependent] && @reflection.options[:dependent] == :delete_all destroy_all else delete_all diff --git a/activerecord/test/fixtures/company.rb b/activerecord/test/fixtures/company.rb index 8de66d9526e237c90e3d6c0571aba0119617be6b..b0694ff361566fbf5e685e528ec5b00117b2f7ce 100755 --- a/activerecord/test/fixtures/company.rb +++ b/activerecord/test/fixtures/company.rb @@ -9,13 +9,13 @@ class Company < ActiveRecord::Base class Firm < Company - has_many :clients, :order => "id", :dependent => true, :counter_sql => + has_many :clients, :order => "id", :dependent => :destroy, :counter_sql => "SELECT COUNT(*) FROM companies WHERE firm_id = 1 " + "AND (#{QUOTED_TYPE} = 'Client' OR #{QUOTED_TYPE} = 'SpecialClient' OR #{QUOTED_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 :dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :destroy + has_many :exclusively_dependent_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id", :dependent => :delete_all has_many :limited_clients, :class_name => "Client", :order => "id", :limit => 1 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}' @@ -29,7 +29,7 @@ class Firm < Company :finder_sql => 'SELECT * FROM companies WHERE client_of = 1000', :counter_sql => 'SELECT COUNT(*) FROM companies WHERE client_of = 1000' - has_one :account, :foreign_key => "firm_id", :dependent => true + has_one :account, :foreign_key => "firm_id", :dependent => :destroy end class DependentFirm < Company diff --git a/activerecord/test/fixtures/company_in_module.rb b/activerecord/test/fixtures/company_in_module.rb index df476520b8948250f492b1cb18c607059ea5635d..7372134ae90bd5616ce0ab76587d55965bf0234e 100644 --- a/activerecord/test/fixtures/company_in_module.rb +++ b/activerecord/test/fixtures/company_in_module.rb @@ -5,13 +5,13 @@ class Company < ActiveRecord::Base end class Firm < Company - has_many :clients, :order => "id", :dependent => true + has_many :clients, :order => "id", :dependent => :destroy 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 :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_one :account, :dependent => true + has_one :account, :dependent => :destroy end class Client < Company diff --git a/activerecord/test/fixtures/reply.rb b/activerecord/test/fixtures/reply.rb index 44a23cd2ddfc511fd53b22a9f39fb24e9f409d44..bf7781e81414d46b2cef168fddbc6b6797f6d81e 100755 --- a/activerecord/test/fixtures/reply.rb +++ b/activerecord/test/fixtures/reply.rb @@ -2,7 +2,7 @@ class Reply < Topic belongs_to :topic, :foreign_key => "parent_id", :counter_cache => true - has_many :replies, :class_name => "SillyReply", :dependent => true, :foreign_key => "parent_id" + has_many :replies, :class_name => "SillyReply", :dependent => :destroy, :foreign_key => "parent_id" validate :errors_on_empty_content validate_on_create :title_is_wrong_create diff --git a/activerecord/test/fixtures/topic.rb b/activerecord/test/fixtures/topic.rb index 1941080ec7b4413fec61d1daa09bab5f83a68fcf..9b20f02cb0efcfe7cccbe035b8d9a8447ab49744 100755 --- a/activerecord/test/fixtures/topic.rb +++ b/activerecord/test/fixtures/topic.rb @@ -1,5 +1,5 @@ class Topic < ActiveRecord::Base - has_many :replies, :dependent => true, :foreign_key => "parent_id" + has_many :replies, :dependent => :destroy, :foreign_key => "parent_id" serialize :content before_create :default_written_on diff --git a/activerecord/test/reflection_test.rb b/activerecord/test/reflection_test.rb index 9b70762a5a06a5f30311a1daf7cb779de87de27c..a409a5a5202f9876fc80883ebe59af152218380d 100644 --- a/activerecord/test/reflection_test.rb +++ b/activerecord/test/reflection_test.rb @@ -77,7 +77,7 @@ def test_aggregation_reflection end def test_has_many_reflection - reflection_for_clients = ActiveRecord::Reflection::AssociationReflection.new(:has_many, :clients, { :order => "id", :dependent => true }, Firm) + reflection_for_clients = ActiveRecord::Reflection::AssociationReflection.new(:has_many, :clients, { :order => "id", :dependent => :destroy }, Firm) assert_equal reflection_for_clients, Firm.reflect_on_association(:clients) @@ -89,7 +89,7 @@ def test_has_many_reflection end def test_has_one_reflection - reflection_for_account = ActiveRecord::Reflection::AssociationReflection.new(:has_one, :account, { :foreign_key => "firm_id", :dependent => true }, Firm) + reflection_for_account = ActiveRecord::Reflection::AssociationReflection.new(:has_one, :account, { :foreign_key => "firm_id", :dependent => :destroy }, Firm) assert_equal reflection_for_account, Firm.reflect_on_association(:account) assert_equal Account, Firm.reflect_on_association(:account).klass