[ALOY-1502] Destroy Model in Alloy doesn't seem to be working
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2016-10-18T19:02:36.000+0000 |
Affected Version/s | Release 5.2.2 |
Fix Version/s | n/a |
Components | Models |
Labels | alloy, destroy |
Reporter | Aminul Islam |
Assignee | Feon Sua Xin Miao |
Created | 2016-06-05T16:42:37.000+0000 |
Updated | 2016-10-18T19:04:55.000+0000 |
Description
Hi,
Trying to delete models using destroy() events seems not working.
Steps to reproduce :
1. Create a simple Alloy project.
2.Create a model TestUser.js
exports.definition = {
config: {
columns: {
'id': 'INTEGER PRIMARY KEY AUTOINCREMENT',
"firstName": "TEXT",
"lastName": "TEXT",
"street": "TEXT"
},
adapter: {
type: "sql",
collection_name: "TestModel",
idAttribute: 'id'
}
}
};
3. Copy the following code in index.js
var user = Alloy.createModel('TestUser');
user.save({id:1, firstName:'aa', lastName:'bb', street:'cc'},{
success:function()
{
Ti.API.info('*** user before destroy\n' + JSON.stringify(user,null,2));
alert('*** user before destroy\n' + JSON.stringify(user,null,2));
user.destroy({
success:function()
{
Ti.API.info('*** user after destroy\n' + JSON.stringify(user,null,2));
alert('*** user after destroy\n' + JSON.stringify(user,null,2));
}
});
}
});
/*
user.fetch();
user.destroy({
success:function()
{
Ti.API.info('*** user after destroy\n' + JSON.stringify(user,null,2));
alert('*** user after destroy\n' + JSON.stringify(user,null,2));
}
});
*/
$.index.open();
4. Run this project
Destroy Model in Alloy doesn't seem to be working, because I get same log before and after destroy();
Log
[INFO] : *** book before destroy
[INFO] : {
[INFO] : "title": "aa2",
[INFO] : "author": "bb2",
[INFO] : "alloy_id": "3da5ac16-aa00-0e52-727d-9ad551f5c850"
[INFO] : }
[INFO] : *** book after destroy
[INFO] : {
[INFO] : "title": "aa2",
[INFO] : "author": "bb2",
[INFO] : "alloy_id": "3da5ac16-aa00-0e52-727d-9ad551f5c850"
[INFO] : }
Environment
Operating System
Name = Mac OS X
Version = 10.11.5
Architecture = 64bit
# CPUs = 4
Memory = 8.0GB
Node.js
Node.js Version = 4.4.4
npm Version = 2.15.1
Appcelerator CLI
Installer = 4.2.6
Core Package = 5.3.0
Titanium CLI
CLI Version = 5.0.8
node-appc Version = 0.2.31
Titanium SDK : 5.3.0.GA
alloy -v : 1.7.33
Thanks
model.destroy
triggers a DELETE event to the database, it doesn't destroy the model object instance stored in memory. Model objects are garbage collected like everything else in JS, and will go away once they are unreachable. To verify, the row is removed from the table: