Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken :only and :except options when serialising an object (as_json) #417

Open
UrsaDK opened this issue Mar 4, 2020 · 1 comment
Open

Comments

@UrsaDK
Copy link
Contributor

UrsaDK commented Mar 4, 2020

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:

@andrykonchin
Copy link
Member

Good catch. It's definitely should be fixed. Added to the backlog.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants