aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-09-05 18:48:10 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-09-05 18:48:10 +0000
commit9d7e6432b22a11e96ad7a3cab7510fac7b3927d6 (patch)
treee2d4d84550401d00a6e0dbe0b38fc6ae475803f5 /activerecord/lib/active_record/base.rb
parentd48322ecca83765a47c054aa72a7165efe9a81f5 (diff)
downloadrails-9d7e6432b22a11e96ad7a3cab7510fac7b3927d6.tar.gz
rails-9d7e6432b22a11e96ad7a3cab7510fac7b3927d6.tar.bz2
rails-9d7e6432b22a11e96ad7a3cab7510fac7b3927d6.zip
Deprecated ActiveRecord::Base.new_record? in favor of ActiveRecord::Base.new? (old version still works until Rails 2.0) [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5017 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rwxr-xr-xactiverecord/lib/active_record/base.rb20
1 files changed, 15 insertions, 5 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index e9c9212560..72155546bd 100755
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -183,7 +183,7 @@ module ActiveRecord #:nodoc:
#
# # No 'Winter' tag exists
# winter = Tag.find_or_initialize_by_name("Winter")
- # winter.new_record? # true
+ # winter.new? # true
#
# == Saving arrays, hashes, and other non-mappable objects in text columns
#
@@ -1518,9 +1518,19 @@ module ActiveRecord #:nodoc:
end
# Returns true if this object hasn't been saved yet -- that is, a record for the object doesn't exist yet.
- def new_record?
+ def new?
@new_record
end
+
+ # Deprecated alias for new?
+ def new_record?
+ ActiveSupport::Deprecation.warn(
+ "ActiveRecord::Base.new_record? has been deprecated and will be removed with Rails 2.0." +
+ "Please use ActiveRecord::Base.new? instead.", caller
+ )
+
+ new?
+ end
# * No record exists: Creates a new record with values matching those of the object attributes.
# * A record does exist: Updates the record with values matching those of the object attributes.
@@ -1538,7 +1548,7 @@ 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).
def destroy
- unless new_record?
+ unless new?
connection.delete <<-end_sql, "#{self.class.name} Destroy"
DELETE FROM #{self.class.table_name}
WHERE #{self.class.primary_key} = #{quoted_id}
@@ -1707,7 +1717,7 @@ module ActiveRecord #:nodoc:
comparison_object.equal?(self) ||
(comparison_object.instance_of?(self.class) &&
comparison_object.id == id &&
- !comparison_object.new_record?)
+ !comparison_object.new?)
end
# Delegates to ==
@@ -1763,7 +1773,7 @@ module ActiveRecord #:nodoc:
private
def create_or_update
- if new_record? then create else update end
+ if new? then create else update end
true
end