dimanche 24 décembre 2017

Creating a record with nested hyperlinked relationship Ember JS

I'm trying to create a record from my EmberJS app into a backend api. The backend api is running Django REST JSON API. Trouble is that I'm using Hyperlinked relationships and for some reason the commit is not able to resolve to the url of the nested resource properly.

For example:

I have an endpoint http://host:port/api/v1/users, user has a belongsTo field which points to group field. On the method that does the creation I am calling

let createdRecordUser = createRecord('user', {'name': 'someName'})

followed by:

createdRecordUser.set('group', groupModelObject)

And finally:

createdRecordUser.save()

This had the undesired effect of sending an OrderedDict into the request.data to Django which then raised an error saying

Type mismatch: Expected URL not OrderedDict

What I was expecting is that the resource would be resolved into it's url on POST.

What the post request is presently sending:

{'name': 'someName', 'group': OrderedDict(['id': 4, 'type': 'normal'])}

What the backend API is expecting:

{'name': 'someName', 'group': 'http://host:port/api/v1/groups/1'}

I'm very new to EmberJS (JS in general) and would appreciate any guidance on how to resolve this issue.

Thank you very much for your time.




Aucun commentaire:

Enregistrer un commentaire