PDA

View Full Version : Model.destroy() does not work



Mike Mandel
25 Feb 2011, 4:16 AM
Hello,

I have problems to delete a user with the new Ext.Data.Model package.
To test it, I simply chained the CRUD operations together.
So first create the new user, then update and finally delete.
Creating and updating works fine, but I canīt delete the user.
In the server logs, I can see the url calls when creating and updating the user.
But there is no url call for delete.
Deleting the user with curl works fine.
The backend is written with the Perl Catalyst Framework using REST style.
Maybe itīs a bug in Ext JS?

Here is my code:


Ext.regModel('User', {
fields: [ 'id', 'name', 'email' ],
proxy: {
type: 'rest',
url: '/user',
reader: {
type: 'json',
root: 'user',
successProperty: 'success'
}
}
});

//create the user
var user = Ext.ModelMgr.create({name: 'Mike', email: 'my@email'}, 'User');
user.save({
success: function(user) {
console.log('ID ' + user.getId());
//update the user
user.set({name: 'Mike Mandel'});
user.save({
success: function(user) {
console.log('user updated ' + user.get('name'));
//delete the user
user.destroy({
success: function(user) {
console.log('user deleted');
},
failure: function(user) {
console.log('user delete failed');
}
});
},
failure: function(user) {
console.log('user update failed');
}
});
},
failure: function(user) {
console.log('user create failed');
}
});
Thanks for your help!

Mike

icflorescu
28 Feb 2011, 7:53 AM
It happens because there's no destroy() method defined on Model yet (dev preview 2).
I believe calling destroy() on any model just falls back to this empty function call:


destroy: function() {} --> line 2394 in ext-core-debug.js


In other words Model.destroy() functionality is not implemented yet in the current developer preview :(

Mike Mandel
28 Feb 2011, 3:21 PM
Thanks for your response!

You are right. It seems, that this function is not yet implemented.
I wrote a simple console.log('destroy()') inside the destroy() function to get some debugging output.

Letīs hope, that it gets fixed in one of the next releases.

Mike