I have a route that pulls data from a REST API. The first time a user enters, there won't be any data saved, so I need to create the record with some default values. I figure I need to do this here in the route so the user can see my default values (which in my actual app aren't just null), rather than creating during the save action.
If, however, there is data in the database, I need to return that record. Right now I'm stuck and must not be doing something right (probably has to do with promises, but I'm not sure).
The error I get is:
Error while processing route: project.dates Assertion Failed:
Expected an object as `data` in a call to `push` for star@model:project-dates: ,
but was undefined
Here's my route code:
var project = this.modelFor('project');
var projectDates = this.store.find('project-dates', project.id);
if (projectDates) {
return projectDates;
} else {
return this.store.createRecord('project-dates', {
project: project.id,
start: null,
checkpointA: null,
finish: null
};
}
The puzzling thing is that if I just negate my if statement to get the other return value (like so: if (!projectDates)) then I still get the error above, but it also loads up the model! I have confirmed that the API (or my mock API) is returning data in the right format, as an object.
Aucun commentaire:
Enregistrer un commentaire