I have a computed property where I'm attempting to create a record if one does not exist, but keep getting a jQuery.Deferred exception
when attempting to render the computed property.
Here's what I have so far:
deadlineDay: computed(function() {
const oneWeekFromNow = moment().startOf('day').add(1, 'week');
const store = this.get('store');
return store.queryRecord('deadline-day', {
filter: {
date: oneWeekFromNow
}
}).then(result => {
if (!result) {
result = store.createRecord('deadline-day', {
date: oneWeekFromNow
});
result.save();
}
return result;
});
}),
Then in my templates I'm attempting to render with a simple helper:
{{display-date deadlineDay.date}}
The {{display-date}}
helper just calls return date.format('dddd, MMM Do')
It looks like Ember is attempting to render the promise itself instead of waiting for it to resolve.
This results in an error since .format
is not a method of the promise.
I imagine this is an extremely common use-case, but that I have a lapse in understanding. Much help appreciated!
I'm not sure if it is relevant, but my backing store is sessionStorage via ember-local-storage