Created
June 20, 2019 10:48
-
-
Save lolmaus/c9cc1b4226f7c58171ee0cdbf5796bd9 to your computer and use it in GitHub Desktop.
Solution for JSONAPIAdapter.updateRecord, DS.InvalidError and record.errors: https://github.com/emberjs/data/issues/6173
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
import RSVP from 'rsvp'; | |
export default DS.JSONAPIAdapter.extend({ | |
updateRecord(store, type, snapshot) { | |
if (snapshot.adapterOptions && snapshot.adapterOptions.withError) { | |
return RSVP.reject(new DS.InvalidError([ | |
{ | |
detail: 'This name is reserved', | |
source: {pointer: '/data/attributes/name'}, | |
}, | |
])); | |
} else { | |
return this._super(store, type, snapshot); | |
} | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Controller.extend({ | |
appName: 'Ember Twiddle', | |
actions: { | |
saveWithError() { | |
this.model.save({adapterOptions: {withError: true}}); | |
}, | |
}, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Model from 'ember-data/model'; | |
import attr from 'ember-data/attr'; | |
import { belongsTo, hasMany } from 'ember-data/relationships'; | |
export default Model.extend({ | |
name: attr('string'), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Ember from 'ember'; | |
export default Ember.Route.extend({ | |
model() { | |
return this.store.push({ | |
data: { | |
id: '1', | |
type: 'my-model', | |
attributes: { | |
name: 'Foo', | |
}, | |
}, | |
}); | |
} | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"version": "0.15.1", | |
"EmberENV": { | |
"FEATURES": {} | |
}, | |
"options": { | |
"use_pods": false, | |
"enable-testing": false | |
}, | |
"dependencies": { | |
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js", | |
"ember": "3.4.3", | |
"ember-template-compiler": "3.4.3", | |
"ember-testing": "3.4.3" | |
}, | |
"addons": { | |
"ember-data": "3.11.0-beta.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment