0
votes

I'm trying to create two new related records at once, and I'm wondering the best way to go about this from Ember Data.

I have a User and a Reminder. I need to create the user first, then create the user's reminder.

I could write my server code to handle a payload like

reminder: {
  text: 'something',
},
user: {
  email: '[email protected]'
}

but, how would I get Ember Data to send that payload? Write a custom serializer? On which model, user or reminder?

Alternatively, should I make the two POST requests separately, first the user then the reminder? Is this more idiomatic?

1

1 Answers

1
votes

Best practices are that a single HTTP request is about a single object. You're going to have to write custom code on both the client and the server to deal with these sorts of combined requests. Better to go with separate POSTs, or find some other optimization if you are worried about excessive network requests,

If, on the other hand, one object is a member of another, then you can quite easily arrange for Ember to send the sub-object in embedded fashion, and then, depending on the capabilities of your server-side ORM, have the sub-object stored separately in its own table or collection if that's what you want.