ember-restless icon indicating copy to clipboard operation
ember-restless copied to clipboard

Enable nonembeddable in save record

Open goneflyin opened this issue 10 years ago • 5 comments

When saving records we need to be able to specify the data without embedding it in a root element. This is known, as the option exists in the JSONSerializer, however it has not been available when using the RESTAdapter.

This passes any options directly on to the serializer. If the serializer doesn't take options, it will be ignored. Should any options ever be needed for the saveRecord method then they can be safely merged into this same parameter.

As no tests currently existed for saveRecord there were none to be modified or easily added. Let me know if there's anything else you need.

goneflyin avatar Apr 20 '15 23:04 goneflyin

@goneflyin a good way to handle this is by extending the JSONSerializer - see: https://github.com/bustlelabs/ember-restless/issues/48#issuecomment-33147427. This way you don't have to pass the nonEmbedded option every time you call saveRecord. Let me know if you have a different use-case that requires passing the options to saveRecord

gpoitch avatar Apr 21 '15 02:04 gpoitch

I was considering overriding the JSONSerializer, but it seemed just a touch heavy-handed. Perhaps it's not, and it's a good approach. I'm not new to development, but fairly new to idiomatic JS and Ember in particular -- if this is the recommended approach, sounds like a straightforward fix!

My only additional thought, having worked in REST APIs for quite a while, is that this feature would better be configurable rather than only through overriding a serializer. That said, there doesn't yet seem to be any consensus on the format of JSON data: HAL, JSON API, Rails conventions, etc. So, perhaps it's just a slippery slope.

I'll use the JSONSerializer-based solution and come back with a more detailed issue or PR if I think of something better. Thanks!

goneflyin avatar Apr 21 '15 03:04 goneflyin

@goneflyin thanks for the feedback. I'm thinking about adding an embedded option as a param directly on Serializers to make this easier, since this has come up a few times now.

gpoitch avatar Apr 21 '15 03:04 gpoitch

:+1:

tylr avatar Apr 21 '15 05:04 tylr

:+1:

damiencriado avatar May 19 '15 01:05 damiencriado