PostgreSQL array columns with normalization

#1542 · closed · 1 comments

View on GitHub ↗

arBmind

Columns that define a normalization like: ```ruby 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: ```ruby 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 end ``` If `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?

Comments

github-actions[bot]

This issue has been automatically marked as stale due to inactivity. The resources of our volunteers are limited. Bug reports must provide a script that reproduces the bug, using our template. Feature suggestions must include a promise to build the feature yourself. Thank you for all your contributions.