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

Single record mode and root false tweaks #54

Conversation

felixbuenemann
Copy link
Collaborator

@felixbuenemann felixbuenemann commented Apr 16, 2016

  • Fallback to ruby serializer for root: false option (until we add support for it)
  • Implement single_record for ruby array serializer (to unify behavior when mixing ruby/db serializers)
  • Auto-singularize root key in single record mode (specifying root: 'singular_name' is now optional)

There currently are no tests for the fallback and single_record behavior, but we should add it after #53 is implemented.

This enables `single_record: true` to work when the ruby array
serializer is used as a fallback which should avoid confusion when
mixing database and ruby serializers.
This change allows to use `single_record: true` mode with collections
without having to specify the `root: 'singular_name'` option. The root
key is only singularized if it was not manually specified via the
options or on the serializer itself.
@@ -51,7 +62,9 @@ def _include_relation_in_root(relation, *args)
end

_serializer = serializer_class.new klass.new, options
root_key = local_options.fetch(:root, _serializer.root_name.to_s.pluralize).to_s
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was buggy, because root option could be nil, causing the fallback to not be used.

@felixbuenemann felixbuenemann merged commit fa1f7b5 into DavyJonesLocker:master Apr 16, 2016
@felixbuenemann felixbuenemann deleted the single-record-mode-and-root-false-tweaks branch April 16, 2016 02:54
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

Successfully merging this pull request may close these issues.

1 participant