File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
activerecord/lib/active_record Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ def associated_table(table_name)
44
44
arel_table = arel_table . alias ( table_name ) if arel_table . name != table_name
45
45
TableMetadata . new ( association_klass , arel_table , reflection )
46
46
else
47
- type_caster = TypeCaster ::Connection . new ( klass )
47
+ type_caster = TypeCaster ::Connection . new ( klass , table_name )
48
48
arel_table = Arel ::Table . new ( table_name , type_caster : type_caster )
49
49
TableMetadata . new ( nil , arel_table , reflection )
50
50
end
Original file line number Diff line number Diff line change 3
3
module ActiveRecord
4
4
module TypeCaster
5
5
class Connection # :nodoc:
6
- def initialize ( klass )
6
+ def initialize ( klass , table_name )
7
7
@klass = klass
8
+ @table_name = table_name
8
9
end
9
10
10
11
def type_cast_for_database ( attr_name , value )
@@ -13,8 +14,20 @@ def type_cast_for_database(attr_name, value)
13
14
end
14
15
15
16
def type_for_attribute ( attr_name )
16
- @klass . type_for_attribute ( attr_name ) || Type . default_value
17
+ schema_cache = @klass . schema_cache
18
+
19
+ if schema_cache . data_source_exists? ( table_name )
20
+ column = schema_cache . columns_hash ( table_name ) [ attr_name . to_s ]
21
+ if column
22
+ type = @klass . with_connection { |connection | connection . lookup_cast_type_from_column ( column ) }
23
+ end
24
+ end
25
+
26
+ type || Type . default_value
17
27
end
28
+
29
+ private
30
+ attr_reader :table_name
18
31
end
19
32
end
20
33
end
You can’t perform that action at this time.
0 commit comments