aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb')
-rw-r--r--activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb32
1 files changed, 22 insertions, 10 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
index 3cf40e6cd4..17fabe5af6 100644
--- a/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
+++ b/activerecord/lib/active_record/connection_adapters/postgresql/quoting.rb
@@ -32,11 +32,7 @@ module ActiveRecord
when 'point' then super(PostgreSQLColumn.point_to_string(value))
when 'json' then super(PostgreSQLColumn.json_to_string(value))
else
- if column.array
- "'#{PostgreSQLColumn.array_to_string(value, column, self).gsub(/'/, "''")}'"
- else
- super
- end
+ super(value, array_column(column))
end
when Hash
case sql_type
@@ -98,11 +94,7 @@ module ActiveRecord
when 'point' then PostgreSQLColumn.point_to_string(value)
when 'json' then PostgreSQLColumn.json_to_string(value)
else
- if column.array
- PostgreSQLColumn.array_to_string(value, column, self)
- else
- super(value, column)
- end
+ super(value, array_column(column))
end
when Hash
case column.sql_type
@@ -185,6 +177,26 @@ module ActiveRecord
super
end
end
+
+ def array_column(column)
+ if column.array && !column.respond_to?(:type_cast_for_database)
+ OID::Array.new(AdapterProxyType.new(column, self))
+ else
+ column
+ end
+ end
+
+ class AdapterProxyType < SimpleDelegator
+ def initialize(column, adapter)
+ @column = column
+ @adapter = adapter
+ super(column)
+ end
+
+ def type_cast_for_database(value)
+ @adapter.type_cast(value, @column)
+ end
+ end
end
end
end