5

Ember Data is moving fast from version to version and the method for saving data has been changing along with it. Right now with version 1.0.0-beta.8.2a68c63a the proper method is to update a record and then do a record.save() to trigger a PUT request back to the server. With my current app I'm updating multiple records at once and that could involve 50+ PUT ajax requests back to the server. We're concerned about performance and efficiency issues and haven't found any documentation for doing batch requests. If anything, we've found a lot of other people online that are looking to do the same thing and haven't found a good solution.

Right now I'm looking into manually serializing these objects and saving them back to the server, which I thought was the entire point of Ember Data. So maybe it's in my best interest to not use Ember Data at all and manually code out CRUD requests and make my own data layer for handling all of this and just use ArrayControllers and ObjectControllers to save the data in and bind to the Handlebars templates. It seems like the benefits to this would be that it would work the way I need it to (batch requests) and the code won't break with future versions of Ember Data. Any thoughts or solutions?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Cory Schulz
  • 319
  • 5
  • 15
  • 2
    If you're talking about multiple resource types, and multiple updates hitting the same endpoint, I'd totally switch away from Ember Data. – Kingpin2k Jun 16 '14 at 19:29
  • Yeah, it involves rearranging a list of blocks on a page and then saving back their position, which means updating all of the blocks. So when you move one, they all shift, which could be 50 to 100 PUT commands back to the server every time. Seems like Ember Data isn't really ready for this. – Cory Schulz Jun 17 '14 at 18:07
  • 2
    Definitely not, you're better off rolling your own implementation, it shouldn't be too heavy. – Kingpin2k Jun 17 '14 at 18:09
  • That's what I figured. So it goes. – Cory Schulz Jun 17 '14 at 18:46
  • I had a similar use case and ended up having to roll my own. http://stackoverflow.com/questions/31412839/is-there-any-way-to-create-a-batch-of-multiple-records-with-a-single-post-reques – Stefan Lyew Aug 26 '15 at 18:58
  • I'm working on a different project now and I use Ember for the router, the controllers objects, and the template compiler (HTMLbars), but I ended up creating my own datastore for basic data management. I'm doing some somewhat complicated stuff with drag and drop environments where I'm dynamically creating objects in the DOM and saving positions back to the server and then pushing updates to other DOM objects, and Ember just wasn't cut out for that type of complex data-DOM interaction. I'm much happier with what I have now and have considered using Sammy.js and ditching Ember, it's too complex. – Cory Schulz Sep 03 '15 at 22:31

1 Answers1

1

You can do it with the DS.EmbeddedRecordsMixin. If your Page object has many Blocks (for example, based on your comment), then page-serializer.js would look like:

import DS from 'ember-data';

export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
  attrs: {
    blocks: { serialize: 'records' }
  }
});

Whenever you save a page record all of its associated blocks records will be included in that one PUT request.

See the documentation here.

andorov
  • 4,197
  • 3
  • 39
  • 52
  • That may be the situation now, but I've stopped using Ember because it's grown too large and complicated to work with. I feel like it's pretty much Sproutcore again. – Cory Schulz Nov 04 '15 at 22:25
  • 1
    No worries. I figured other people might come across this. – andorov Nov 04 '15 at 22:33