aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-09-22 21:35:35 +0200
committerMichael Koziarski <michael@koziarski.com>2008-09-22 21:35:35 +0200
commit638bd19c7fdf4a4c09bfa5b4ada23c6f37724f9b (patch)
treec27414d94e86b396fe716e031a6fafb0fc8ca575 /activerecord/lib/active_record
parent5795c509a7c0ab9c6d3d707f34526430e58e535c (diff)
parent5f86451a4c5d0beca5a746c4708be48b13f665be (diff)
downloadrails-638bd19c7fdf4a4c09bfa5b4ada23c6f37724f9b.tar.gz
rails-638bd19c7fdf4a4c09bfa5b4ada23c6f37724f9b.tar.bz2
rails-638bd19c7fdf4a4c09bfa5b4ada23c6f37724f9b.zip
Merge branch 'patches' into multibyte
Diffstat (limited to 'activerecord/lib/active_record')
-rwxr-xr-xactiverecord/lib/active_record/associations.rb4
-rw-r--r--activerecord/lib/active_record/associations/association_collection.rb7
-rwxr-xr-xactiverecord/lib/active_record/base.rb10
-rw-r--r--activerecord/lib/active_record/version.rb2
4 files changed, 17 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb
index e6491cebd6..6f4be9391b 100755
--- a/activerecord/lib/active_record/associations.rb
+++ b/activerecord/lib/active_record/associations.rb
@@ -1470,7 +1470,7 @@ module ActiveRecord
method_name = "has_one_dependent_delete_for_#{reflection.name}".to_sym
define_method(method_name) do
association = send(reflection.name)
- association.class.delete(association.id) unless association.nil?
+ association.delete unless association.nil?
end
before_destroy method_name
when :nullify
@@ -1500,7 +1500,7 @@ module ActiveRecord
method_name = "belongs_to_dependent_delete_for_#{reflection.name}".to_sym
define_method(method_name) do
association = send(reflection.name)
- association.class.delete(association.id) unless association.nil?
+ association.delete unless association.nil?
end
before_destroy method_name
else
diff --git a/activerecord/lib/active_record/associations/association_collection.rb b/activerecord/lib/active_record/associations/association_collection.rb
index afb817f8ae..47a09510c8 100644
--- a/activerecord/lib/active_record/associations/association_collection.rb
+++ b/activerecord/lib/active_record/associations/association_collection.rb
@@ -63,7 +63,7 @@ module ActiveRecord
# Fetches the first one using SQL if possible.
def first(*args)
- if fetch_first_or_last_using_find? args
+ if fetch_first_or_last_using_find?(args)
find(:first, *args)
else
load_target unless loaded?
@@ -73,7 +73,7 @@ module ActiveRecord
# Fetches the last one using SQL if possible.
def last(*args)
- if fetch_first_or_last_using_find? args
+ if fetch_first_or_last_using_find?(args)
find(:last, *args)
else
load_target unless loaded?
@@ -420,7 +420,8 @@ module ActiveRecord
end
def fetch_first_or_last_using_find?(args)
- args.first.kind_of?(Hash) || !(loaded? || @owner.new_record? || @reflection.options[:finder_sql] || !@target.blank? || args.first.kind_of?(Integer))
+ args.first.kind_of?(Hash) || !(loaded? || @owner.new_record? || @reflection.options[:finder_sql] ||
+ @target.any? { |record| record.new_record? } || args.first.kind_of?(Integer))
end
end
end
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index b20da512eb..3aa8e5541d 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -2306,6 +2306,16 @@ module ActiveRecord #:nodoc:
# Deletes the record in the database and freezes this instance to reflect that no changes should
# be made (since they can't be persisted).
+ #
+ # Unlike #destroy, this method doesn't run any +before_delete+ and +after_delete+
+ # callbacks, nor will it enforce any association +:dependent+ rules.
+ def delete
+ self.class.delete(id) unless new_record?
+ freeze
+ end
+
+ # Deletes the record in the database and freezes this instance to reflect that no changes should
+ # be made (since they can't be persisted).
def destroy
unless new_record?
connection.delete <<-end_sql, "#{self.class.name} Destroy"
diff --git a/activerecord/lib/active_record/version.rb b/activerecord/lib/active_record/version.rb
index aaadef9979..2479b75789 100644
--- a/activerecord/lib/active_record/version.rb
+++ b/activerecord/lib/active_record/version.rb
@@ -1,7 +1,7 @@
module ActiveRecord
module VERSION #:nodoc:
MAJOR = 2
- MINOR = 1
+ MINOR = 2
TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')