Skip to content

Commit 6dd1929

Browse files
committed
Eliminate lease_connection call in TypeCaster::Connection
1 parent 7082d34 commit 6dd1929

File tree

2 files changed

+3
-16
lines changed

2 files changed

+3
-16
lines changed

activerecord/lib/active_record/table_metadata.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def associated_table(table_name)
4444
arel_table = arel_table.alias(table_name) if arel_table.name != table_name
4545
TableMetadata.new(association_klass, arel_table, reflection)
4646
else
47-
type_caster = TypeCaster::Connection.new(klass, table_name)
47+
type_caster = TypeCaster::Connection.new(klass)
4848
arel_table = Arel::Table.new(table_name, type_caster: type_caster)
4949
TableMetadata.new(nil, arel_table, reflection)
5050
end

activerecord/lib/active_record/type_caster/connection.rb

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
module ActiveRecord
44
module TypeCaster
55
class Connection # :nodoc:
6-
def initialize(klass, table_name)
6+
def initialize(klass)
77
@klass = klass
8-
@table_name = table_name
98
end
109

1110
def type_cast_for_database(attr_name, value)
@@ -14,20 +13,8 @@ def type_cast_for_database(attr_name, value)
1413
end
1514

1615
def type_for_attribute(attr_name)
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.lease_connection.lookup_cast_type_from_column(column)
23-
end
24-
end
25-
26-
type || Type.default_value
16+
@klass.type_for_attribute(attr_name) || Type.default_value
2717
end
28-
29-
private
30-
attr_reader :table_name
3118
end
3219
end
3320
end

0 commit comments

Comments
 (0)