-
Notifications
You must be signed in to change notification settings - Fork 908
Open
Description
Columns that define a normalization like:
normalizes :nos, with: ->(value) { value&.reject(&:nil?)&.uniq&.sort }Are not detected by paper_trail to contain arrays. As the type is wrapped with a ActiveRecord::Normalization::NormalizedValueType.
My Workaround:
PaperTrail::AttributeSerializers::AttributeSerializerFactory.redefine_singleton_method :ar_pg_array? do |obj|
if defined?(::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array)
if obj.respond_to?(:cast_type)
obj.cast_type.instance_of?(::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array)
else
obj.instance_of?(::ActiveRecord::ConnectionAdapters::PostgreSQL::OID::Array)
end
else
false
end
endIf paper_trail fails to detect the array, the serialization becomes a hash with a values key that contains the array itself. But later fails do deserialize the json to a proper array.
Would it be better to use columns_hash[name].array to detect arrays and store use a noop-array-serializer, that is independent of Postgres?
Metadata
Metadata
Assignees
Labels
No labels