Reputation: 2816
I have a detailed observation for this. Not sure what I am doing wrong here. I have a model definition where I compute a boolean value. Which causing the deleteRecord()
method to send data with a wrong request method (POST
instead of DELETE
). Also when I call save()
method it sends the request through PUT
instead of POST
Please note: Code works fine when I remove the computed property definition.
var attr = DS.attr(),
string = DS.attr('string'),
boolean = DS.attr('boolean'),
number = DS.attr('number'),
hasMany = DS.hasMany();
App.Status = DS.Model.extend({
sticky: boolean,
title: string,
date: string,
categories: attr,
content: string,
comment_allowed: boolean,
replying: DS.attr('boolean', {defaultValue: false}),
isNew: function(){
var unix = parseInt( moment(this.get('date')).format('X') );
var current = parseInt(moment().format('X'));
var four_hours = 60 * 60 * 4;
return ( (unix + four_hours) > current);
}.property('date')
});
When I try to delete the record form an action handler destroyRecord()
make ajax request with POST
instead of DELETE
. Also the request url is wrong. It gets sends to /statuses
instead of /status/id
App.IndexController = Ember.ArrayController.extend({
actions: {
deleteStatus: function(status_id){
if(!confirm('Are you sure you want to delete this status?'))
return;
this.store.find('status', status_id).then(function(status){
console.log(status);
status.destroyRecord();
});
}
}
});
Also note that the computed property function working as expected without any errors.
Find the code for RESTAdapter
below. Again if I comment out the Computed Property part the code works fine.
App.ApplicationAdapter = DS.RESTAdapter.extend({
host: config.siteUrl,
namespace: 'wp-json',
headers: {
"X-WP-Nonce": config.nonce
}
});
Upvotes: 2
Views: 173
Reputation: 13526
You can't use isNew
for a property name, as ember-data is already using that for its own purposes. Try changing the property to isRecent
or something similar.
Upvotes: 2