mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #39515 from kamipo/type_for_attribute_be_aware_of_attribute_aliases
Support attribute aliases for `type_for_attribute`
This commit is contained in:
commit
aaf20e3c7e
3 changed files with 5 additions and 2 deletions
|
@ -381,6 +381,8 @@ module ActiveRecord
|
|||
# a string or a symbol.
|
||||
def type_for_attribute(attr_name, &block)
|
||||
attr_name = attr_name.to_s
|
||||
attr_name = attribute_aliases[attr_name] || attr_name
|
||||
|
||||
if block
|
||||
attribute_types.fetch(attr_name, &block)
|
||||
else
|
||||
|
|
|
@ -344,12 +344,11 @@ module ActiveRecord
|
|||
|
||||
def compute_cache_version(timestamp_column) # :nodoc:
|
||||
timestamp_column = timestamp_column.to_s
|
||||
timestamp_column = klass.attribute_aliases[timestamp_column] || timestamp_column
|
||||
|
||||
if loaded? || distinct_value
|
||||
size = records.size
|
||||
if size > 0
|
||||
timestamp = records.map { |record| record._read_attribute(timestamp_column) }.max
|
||||
timestamp = records.map { |record| record.read_attribute(timestamp_column) }.max
|
||||
end
|
||||
else
|
||||
collection = eager_loading? ? apply_join_dependency : self
|
||||
|
|
|
@ -69,6 +69,8 @@ class ReflectionTest < ActiveRecord::TestCase
|
|||
assert_equal :string, @first.column_for_attribute(:title).type
|
||||
assert_equal :string, @first.type_for_attribute("title").type
|
||||
assert_equal :string, @first.type_for_attribute(:title).type
|
||||
assert_equal :string, @first.type_for_attribute("heading").type
|
||||
assert_equal :string, @first.type_for_attribute(:heading).type
|
||||
assert_equal 250, @first.column_for_attribute("title").limit
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue