diff options
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 9ec7c1ecaf..0ce876d7a9 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1507,6 +1507,7 @@ module ActiveRecord #:nodoc: @attributes = attributes_from_column_definition @attributes_cache = {} @new_record = true + @readonly = false ensure_proper_type if scope = self.class.send(:current_scoped_methods) @@ -1571,7 +1572,7 @@ module ActiveRecord #:nodoc: # user_path(user) # => "/users/Phusion" def to_param # We can't use alias_method here, because method 'id' optimizes itself on the fly. - (id = self.id) ? id.to_s : nil # Be sure to stringify the id for routes + id && id.to_s # Be sure to stringify the id for routes end # Returns a cache key that can be used to identify this record. @@ -1696,7 +1697,7 @@ module ActiveRecord #:nodoc: # This is especially useful for boolean flags on existing records. The regular +update_attribute+ method # in Base is replaced with this when the validations module is mixed in, which it is by default. def update_attribute(name, value) - send(name.to_s + '=', value) + send("#{name}=", value) save(:validate => false) end @@ -1913,14 +1914,14 @@ module ActiveRecord #:nodoc: # Returns duplicated record with unfreezed attributes. def dup obj = super - obj.instance_variable_set('@attributes', instance_variable_get('@attributes').dup) + obj.instance_variable_set('@attributes', @attributes.dup) obj end # Returns +true+ if the record is read only. Records loaded through joins with piggy-back # attributes will be marked as read only since they cannot be saved. def readonly? - defined?(@readonly) && @readonly == true + @readonly end # Marks this record as read only. @@ -1940,10 +1941,10 @@ module ActiveRecord #:nodoc: protected def clone_attributes(reader_method = :read_attribute, attributes = {}) - self.attribute_names.inject(attributes) do |attrs, name| - attrs[name] = clone_attribute_value(reader_method, name) - attrs + attribute_names.each do |name| + attributes[name] = clone_attribute_value(reader_method, name) end + attributes end def clone_attribute_value(reader_method, attribute_name) @@ -2246,4 +2247,4 @@ end # TODO: Remove this and make it work with LAZY flag require 'active_record/connection_adapters/abstract_adapter' -ActiveRecord.run_base_hooks(ActiveRecord::Base)
\ No newline at end of file +ActiveRecord.run_base_hooks(ActiveRecord::Base) |