Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move attribute_types_cached_by_default into attribute methods reading…

… concern
  • Loading branch information...
commit d599ea27c563af2a79ccad3cabc0a1efd4c2427f 1 parent 89e9efc
Joshua Peek josh authored
10 activerecord/lib/active_record/attribute_methods.rb
View
@@ -4,13 +4,6 @@ module ActiveRecord
module AttributeMethods #:nodoc:
extend ActiveSupport::Concern
- ATTRIBUTE_TYPES_CACHED_BY_DEFAULT = [:datetime, :timestamp, :time, :date]
-
- included do
- cattr_accessor :attribute_types_cached_by_default, :instance_writer => false
- self.attribute_types_cached_by_default = ATTRIBUTE_TYPES_CACHED_BY_DEFAULT
- end
-
# Declare and check for suffixed attribute methods.
module ClassMethods
# Declares a method available for all attributes with the given suffix.
@@ -77,9 +70,6 @@ def define_attribute_methods
end
end
end
- unless generated_methods.include?("id")
- define_read_method(:id, primary_key, columns_hash[primary_key.to_s])
- end
end
def undefine_attribute_methods
11 activerecord/lib/active_record/attribute_methods/read.rb
View
@@ -3,8 +3,15 @@ module AttributeMethods
module Read
extend ActiveSupport::Concern
+ ATTRIBUTE_TYPES_CACHED_BY_DEFAULT = [:datetime, :timestamp, :time, :date]
+
included do
attribute_method_suffix ""
+
+ cattr_accessor :attribute_types_cached_by_default, :instance_writer => false
+ self.attribute_types_cached_by_default = ATTRIBUTE_TYPES_CACHED_BY_DEFAULT
+
+ # Undefine id so it can be used as an attribute name
undef_method :id
end
@@ -35,6 +42,10 @@ def define_attribute_method(attr_name)
else
define_read_method(attr_name.to_sym, attr_name, columns_hash[attr_name])
end
+
+ if attr_name == primary_key && attr_name != "id"
+ define_read_method(:id, attr_name, columns_hash[attr_name])
+ end
end
private
Please sign in to comment.
Something went wrong with that request. Please try again.