Ember data 1.0.0-beta4 “Adding unsaved records to hasMany relationships after they are normal” broke my code by duplicating child items after save operation on parent
There was commit to Ember data and delivered with ember-data 1.0.0.-beta4 that broke my code.
Just in case you face similar issue, sharing this with you.
In that commit guy fixes issue with oneToMany relationship, when child items if they were not saved (i.e. are still in ‘isNew’ state) won’t be in list of child items after parent got saved. Apparently this happens because server doesn’t return unsaved child items.
Please see my comment and corresponding commit: https://github.com/emberjs/data/commit/829753e4cb66d6ac93bac5b9983ed7056633d266#commitcomment-4969509
This is completely fine for traditional REST backend that handles each item separately, but what we implemented at work is backend that handles parent item with all child items. So request/response is complete graph. In our case all child items are automatically saved with parent object. Since server returns child item it will be in list of child items. Instead code that guy committed will add child item once again, since object in memory is still with ‘isNew’ state.
This is my fix, that I’ve added to our DS.ApplicationStore
Basically it recursively marks all child items as committed before base didSaveRecord is called and attempts to add them if state is ‘isNew’.
You can notice that changing state is bit crazy – calling adapterWillCommit and adapterDidCommit, but it was only one way I found to do this. Unfortunately state manager is no longer part of ember.
Hope this helps someone.
[Update 2015/07/08: Looks like this got fixed as of ember-data 1.0.0.-beta4]
This website uses cookies. We'll assume you're ok with this, but you can opt-out if you wish.AcceptRead More
Privacy & Cookies Policy
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
code
more code
~~~~