Prevent submitting a newly created record (sub object) to the store using
Ember.data
My models (simplified in this code example)
App.TemplateItem = DS.Model.extend({
someProperty: DS.attr('number'),
contentBlock: DS.belongsTo('App.ContentBlock')
});
App.ContentBlock = DS.Model.extend({
htmlContent: DS.attr('string')
});
DS.WebAPIAdapter.map('App.TemplateItem', {
contentBlock: { embedded: 'always' }
});
My server store internally represents these two models as single class
(ContentBlock inherits from TemplateItem – there are other TemplateItem
types with different properties).
Now, when I create an TemplateItem+ContentBlock in a single step:
newTemplateItem = App.TemplateItem.createRecord({
someProperty: 23,
contentBlock: App.ContentBlock.createRecord({
htmlContent: 'New block...',
})
});
and commit the data
newTemplateItem.get('store').commit();
both TemplateItem and ContentBlock POST requests are launched. But since
my API already creates the server-side object from the TemplateItem POST
request (it contains the nested ContentBlock object), I don't need the
ContentBlock being posted to the API service.
Is there a way to tell Ember data / adapter that it doesn't need to send
the second, nested object? The problem is that even if I create a dummy
server-side API method which doesn't do nothing, I still need to return
the object (which I can't create because of the limitations of the
server-side implementation I described above).
No comments:
Post a Comment