Ember Data save/then with related models not adding associations?

Hey hey all, I put together a quick JSBin to elaborate on the questions I have here: http://jsbin.com/isopaHey/10/edit

The idea is a very simple one to many setup – product has many reviews. Reviews are being sorted in a controller, and there’s an action on the ProductController to create new reviews. It’s using Ember Data Fixtures.

There’s a few questions I’m still trying to find the best answer for that are in the JSBin, but i’ll repeat them here too:

  1. There’s a property in the controller for the current review text that’s cleared out after save. It shouldn’t happen until the then callback though, which doesn’t have access to the controller. Any suggestions on a possible way of handling this?

  2. After save in the then callback, I’m needing to do something like product.get('reviews').addObject(review); in order to have the interface update accordingly. From how I understand it, just calling store.createRecord has added it to the store, and save has updated it with an id and all that. Not sure if/why I need to do this here. Shouldn’t it already be added? Or is there another way it should be created?

  3. Is there a way to simulate failure with the FixtureAdapter?

  4. Unrelated question to Ember Data, but curious about it as well: Sorting for comments isn’t working correctly with newly added comments. It sorts correctly on page load, but the added reviews aren’t sorted correctly.

Also, if anyone has any other comments/suggestions on how they’d structure this code, I’m all ears. :smile:

Just keep a reference to the controller in a local variable

I’ve run unto a similar situation and for now have just used the same workaround as you. I’d like to know if it’s expected behaviour though…

I think it’s because the fixture adapter expects its data in the unserilaised format. I changed your fixtures to call getTime() on the date objects and it seems to be working correctly…

You can see my tweaks to address your questions 1) and 4) here: