dynamoid
dynamoid copied to clipboard
Broken :only and :except options when serialising an object (as_json)
Dynamoid relies on ActiveModel to do the serialisation of Document objects. This should allow us to filter document attributes via a custom as_json method, when a document is serialised to JSON. Eg:
class MyDocument
include Dynamoid::Document
...
def as_json(options = {})
super(options.merge(except: [:id]))
end
Unfortunately, this doesn't work as expected because ActiveModel::Serialization.serializable_hash expects attributes.keys to return an array of strings, not symbols:
- https://github.com/rails/rails/blob/v6.0.2.1/activemodel/lib/active_model/serialization.rb#L133
Good catch. It's definitely should be fixed. Added to the backlog.