Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migrating Active Model Serializer from 0.8 to 0.10 rc2

We've got an API built with Grape and Active Model Serializers 0.8. Now we would like to use all the caching goodness from 0.10, so a migration to the new backwards-incompatible version is in progress.

There are currently two issues right now:

  1. It doesn't seem possible to redefine the root key with self.root= inside serializers. E.g. we've got SimpleUserSerializer and we want the root key to user instead of simple_user. A solution is to specify the root when rendering the serializer, but then we need to make the change in many places. Is there a way to redefine the root key for this serializers regardless of where/how it's rendered?

  2. embed :ids, include: true option is not supported and should probably be implemented through an adapter. Are there any plans on releasing or maintaining 0.8-compatible adapter for legacy projects?

Any guidance about the migration would be helpful as I couldn't find any official documentation.

like image 920
Damir Zekić Avatar asked Nov 09 '22 08:11

Damir Zekić


1 Answers

The first issue can be resolved by defining class method root_name which returns the root key. This can be seen in fixtures in AMS tests.

Still working on the second issue.

like image 179
Damir Zekić Avatar answered Jan 04 '23 02:01

Damir Zekić