From c5e109bbe766b0407a909361f18d2b87e9bfc75c Mon Sep 17 00:00:00 2001 From: Pratik Naik Date: Mon, 18 May 2009 21:27:42 +0200 Subject: Make sure default_scope#create checks for options[:conditions] [#2181 state:resolved] [James Le Cuirot] --- activerecord/lib/active_record/base.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index ca4f4fa6b6..968b9bde5a 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -2176,7 +2176,7 @@ module ActiveRecord #:nodoc: # default_scope :order => 'last_name, first_name' # end def default_scope(options = {}) - self.default_scoping << { :find => options, :create => (options.is_a?(Hash) && options.has_key?(:conditions)) ? options[:conditions] : {} } + self.default_scoping << { :find => options, :create => options[:conditions].is_a?(Hash) ? options[:conditions] : {} } end # Test whether the given method and optional key are scoped. -- cgit v1.2.3 From cef76c8af4705dc60f85a721e3a14adb99418d33 Mon Sep 17 00:00:00 2001 From: Luca Guidi Date: Mon, 16 Mar 2009 13:30:30 +0100 Subject: Ensure HasManyThroughAssociation#destroy delete orphan records [#2251 state:resolved] Signed-off-by: Pratik Naik --- .../lib/active_record/associations/has_many_through_association.rb | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/associations/has_many_through_association.rb b/activerecord/lib/active_record/associations/has_many_through_association.rb index 2dca84b911..e8dbae9011 100644 --- a/activerecord/lib/active_record/associations/has_many_through_association.rb +++ b/activerecord/lib/active_record/associations/has_many_through_association.rb @@ -17,6 +17,13 @@ module ActiveRecord end end + def destroy(*records) + transaction do + delete_records(flatten_deeper(records)) + super + end + end + # Returns the size of the collection by executing a SELECT COUNT(*) query if the collection hasn't been loaded and # calling collection.size if it has. If it's more likely than not that the collection does have a size larger than zero, # and you need to fetch that collection afterwards, it'll take one fewer SELECT query if you use #length. -- cgit v1.2.3