lib/torque/postgresql/adapter/quoting.rb in torque-postgresql-2.4.5 vs lib/torque/postgresql/adapter/quoting.rb in torque-postgresql-3.0.0
- old
+ new
@@ -20,30 +20,22 @@
schema = schema || name_schema || 'public'
Name.new(schema, table).quoted
end
def quote_default_expression(value, column)
- return super unless value.class <= Array &&
- ((column.is_a?(ColumnDefinition) && column.dig(:options, :array)) ||
- (column.is_a?(Column) && column.array?))
+ return super unless value.class <= Array || value.class <= Set
- type = column.is_a?(Column) ? column.sql_type_metadata.sql_type : column.sql_type
- quote(value) + '::' + type
- end
+ type =
+ if column.is_a?(ColumnDefinition) && column.options.try(:[], :array)
+ # This is the general way
+ lookup_cast_type(column.sql_type)
+ elsif column.is_a?(Column) && column.array?
+ # When using +change_column_default+
+ lookup_cast_type_from_column(column)
+ end
- private
-
- def _quote(value)
- return super unless value.is_a?(Array)
-
- values = value.map(&method(:quote))
- "ARRAY[#{values.join(','.freeze)}]"
- end
-
- def _type_cast(value)
- return super unless value.is_a?(Array)
- value.map(&method(:quote)).join(','.freeze)
- end
+ type.nil? ? super : quote(type.serialize(value.to_a))
+ end
end
end
end
end