I am using Ember 1.13.5 and Ember Data 1.13.7 and the default JSONAPIAdapter/Serializer and I have a problem saving a new model.
My route looks like this:
import Ember from 'ember';
export default Ember.Route.extend({
model: function(params) {
return Ember.RSVP.hash({
auditLog: this.store.query('log', {filter: {object: 'IsoApplication', object_id: params.id}}),
});
},
});
This successfully returns a collection of "log" models in the "auditLog" key of the controller, e.g. this.get('model.auditLog').
In the controller I create a new "log" model and save it successfully like this:
self = this;
var log = this.store.createRecord('log', {
logLevelId: 2
logTypeId: 2
object: 'IsoApplication',
objectId: 23
message: 'A message',
logData: '',
});
log.save().then(function(log) {
self.get('model.auditLog').pushObject(log);
});
I use this line:
self.get('model.auditLog').pushObject(log);
To update the model so that my new log entry is displayed in the UI but I get the following error:
TypeError: internalModel.getRecord is not a function
and the "log" parameter in the "save" callback is of type "InternalModel". I was led to believe that InternalModels were only used by the Ember Data core code so presumably the "save" callback should return a DS.Model instance instead. Is something wrong here?
Also, am I doing the correct thing by using "pushObject" to update the "model.auditLog" collection of "log" models in order that the UI updates with the newly added model or should it be an automatic process?
Any help that anyone could offer would be appreciated.
Thanks.
Aucun commentaire:
Enregistrer un commentaire