postgres_ext-serializers icon indicating copy to clipboard operation
postgres_ext-serializers copied to clipboard

Support for {root: false}

Open einarj opened this issue 11 years ago • 3 comments

First of all, thanks for an awesome project.


When I render with plain active model serializers with

render :json => @events, root: false

It produces an array of objects.

However when I put postgres_ext-serializers in place, it returns

{"events": [same array as before]}

In other words, the option of removing the root does not seem to be working.

einarj avatar Oct 22 '14 10:10 einarj

Thanks for reporting this! This project is far from done at the moment, so this is one of the options yet to be implemented. I guess that is "by design" so far, but realistically, it just needs to be added in!

danmcclain avatar Oct 24 '14 15:10 danmcclain

Currently experiencing this issue. :+1: If we can get it in.

BenMorganIO avatar Apr 07 '15 08:04 BenMorganIO

This shouldn't be too hard to add for the embed :ids case or if no associations are present. I looked at the original AMS implementation and it only support root: false if sideloading is not used. Otherwise an error is raised:

ActiveModel::Serializer::IncludeError: Cannot serialize foos when FooSerializer does not have a root!

This can be worked around by forcibly excluding all embedded records using the include: [] option.

Supporting embed: :objects would probably be much harder, because I think it can embed objects recursively, which would require quite some changes in the postgres code.

felixbuenemann avatar Apr 16 '16 02:04 felixbuenemann