{ "id": "160792", "key": "ALOY-1502", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "11113", "key": "ALOY", "name": "Alloy", "projectCategory": { "id": "10400", "description": "Tools for developing applications", "name": "Tooling" } }, "fixVersions": [], "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2016-10-18T19:02:36.000+0000", "created": "2016-06-05T16:42:37.000+0000", "priority": { "name": "Critical", "id": "1" }, "labels": [ "alloy", "destroy" ], "versions": [ { "id": "18001", "name": "Release 5.2.2", "archived": false, "released": true, "releaseDate": "2016-06-28" } ], "issuelinks": [], "assignee": { "name": "fmiao", "key": "fmiao", "displayName": "Feon Sua Xin Miao", "active": true, "timeZone": "America/Vancouver" }, "updated": "2016-10-18T19:04:55.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "13605", "name": "Models" } ], "description": "Hi,\r\nTrying to delete models using destroy() events seems not working.\r\nSteps to reproduce :\r\n1. Create a simple Alloy project.\r\n2.Create a model TestUser.js\r\n{code}\r\nexports.definition = {\r\n\tconfig: {\r\n\t\tcolumns: {\r\n\t\t\t'id': 'INTEGER PRIMARY KEY AUTOINCREMENT',\r\n\t\t \"firstName\": \"TEXT\",\r\n\t\t \"lastName\": \"TEXT\",\r\n\t\t \"street\": \"TEXT\"\r\n\t\t},\r\n\t\tadapter: {\r\n\t\t\ttype: \"sql\",\r\n\t\t\tcollection_name: \"TestModel\",\r\n\t\t\tidAttribute: 'id'\r\n\t\t}\r\n\t}\r\n};\r\n{code}\r\n3. Copy the following code in index.js \r\n{code}\r\nvar user = Alloy.createModel('TestUser');\r\nuser.save({id:1, firstName:'aa', lastName:'bb', street:'cc'},{\r\n\tsuccess:function()\r\n\t{\r\n\t\tTi.API.info('*** user before destroy\\n' + JSON.stringify(user,null,2));\r\n\t\talert('*** user before destroy\\n' + JSON.stringify(user,null,2));\r\n\t\tuser.destroy({\r\n\t\t\tsuccess:function()\r\n\t\t\t{\r\n\t\t\t\tTi.API.info('*** user after destroy\\n' + JSON.stringify(user,null,2));\r\n\t\t\t\talert('*** user after destroy\\n' + JSON.stringify(user,null,2));\r\n\t\t\t}\r\n\t\t});\r\n\t\t\r\n\t}\r\n});\r\n/*\r\nuser.fetch();\r\nuser.destroy({\r\n\tsuccess:function()\r\n\t{\r\n\t\tTi.API.info('*** user after destroy\\n' + JSON.stringify(user,null,2));\r\n\t\talert('*** user after destroy\\n' + JSON.stringify(user,null,2));\r\n\t}\r\n});\r\n*/\r\n$.index.open();\r\n{code}\r\n4. Run this project\r\n\r\nDestroy Model in Alloy doesn't seem to be working, because I get same log before and after destroy();\r\n\r\nLog\r\n{code}\r\n[INFO] : *** book before destroy\r\n\r\n[INFO] : {\r\n\r\n[INFO] : \"title\": \"aa2\",\r\n\r\n[INFO] : \"author\": \"bb2\",\r\n\r\n[INFO] : \"alloy_id\": \"3da5ac16-aa00-0e52-727d-9ad551f5c850\"\r\n\r\n[INFO] : }\r\n\r\n[INFO] : *** book after destroy\r\n\r\n[INFO] : {\r\n\r\n[INFO] : \"title\": \"aa2\",\r\n\r\n[INFO] : \"author\": \"bb2\",\r\n\r\n[INFO] : \"alloy_id\": \"3da5ac16-aa00-0e52-727d-9ad551f5c850\"\r\n\r\n[INFO] : }\r\n\r\n{code}\r\n\r\nEnvironment \r\n{code}\r\nOperating System\r\n Name = Mac OS X\r\n Version = 10.11.5\r\n Architecture = 64bit\r\n # CPUs = 4\r\n Memory = 8.0GB\r\n\r\nNode.js\r\n Node.js Version = 4.4.4\r\n npm Version = 2.15.1\r\n\r\nAppcelerator CLI\r\n Installer = 4.2.6\r\n Core Package = 5.3.0\r\n\r\nTitanium CLI\r\n CLI Version = 5.0.8\r\n node-appc Version = 0.2.31\r\nTitanium SDK : 5.3.0.GA\r\nalloy -v : 1.7.33\r\n\r\n{code}\r\n\r\n\r\nThanks", "attachment": [], "flagged": false, "summary": "Destroy Model in Alloy doesn't seem to be working", "creator": { "name": "aislam", "key": "aislam", "displayName": "Aminul Islam", "active": false, "timeZone": "Etc/GMT-6" }, "subtasks": [], "reporter": { "name": "aislam", "key": "aislam", "displayName": "Aminul Islam", "active": false, "timeZone": "Etc/GMT-6" }, "environment": null, "closedSprints": [ { "id": 732, "state": "closed", "name": "2016 Sprint 21 Tooling", "startDate": "2016-10-08T00:54:00.000Z", "endDate": "2016-10-22T00:54:00.000Z", "completeDate": "2016-10-24T04:18:13.798Z", "originBoardId": 199 } ], "comment": { "comments": [ { "id": "399282", "author": { "name": "fmiao", "key": "fmiao", "displayName": "Feon Sua Xin Miao", "active": true, "timeZone": "America/Vancouver" }, "body": "{{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.\r\n\r\nTo verify, the row is removed from the table:\r\n{code}\r\nvar user = Alloy.createModel('TestUser');\r\nuser.save({id:1, firstName:'aa', lastName:'bb', street:'cc'},{\r\n\tsuccess: function() {\r\n\t\tTi.API.info('|************************************');\r\n\t\tTi.API.info('*** user before destroy\\n' + JSON.stringify(user,null,2));\r\n\r\n\t\tvar db = Ti.Database.open('_alloy_');\r\n\t\tvar sql = 'SELECT * FROM TestModel';\r\n\t\tvar rs = db.execute(sql);\r\n\t\twhile (rs.isValidRow()) {\r\n\t\t\tTi.API.info(rs.fieldByName('id') + ' ' + rs.fieldByName('firstName') + ' ' + rs.fieldByName('lastName'));\r\n\t\t\trs.next();\r\n\t\t}\r\n\t\trs.close();\r\n\r\n\t\tuser.destroy({\r\n\t\t\tsuccess: function(model, response) {\r\n\t\t\t\tTi.API.info('*** user after destroy\\n' + JSON.stringify(user,null,2));\r\n\t\t\t\trs = db.execute(sql);\r\n\t\t\t\twhile (rs.isValidRow()) {\r\n\t\t\t\t\tTi.API.info(rs.fieldByName('id') + ' ' + rs.fieldByName('firstName') + ' ' + rs.fieldByName('lastName'));\r\n\t\t\t\t\trs.next();\r\n\t\t\t\t}\r\n\r\n\t\t\t\trs.close();\r\n\t\t\t\tdb.close();\r\n\t\t\t\tTi.API.info('************************************|');\r\n\t\t\t},\r\n\t\t\terror: function(err){\r\n\t\t\t\tTi.API.info('error');\r\n\t\t\t\tTi.API.info(err);\r\n\t\t\t}\r\n\t\t});\r\n\t}\r\n});\r\n{code}", "updateAuthor": { "name": "fmiao", "key": "fmiao", "displayName": "Feon Sua Xin Miao", "active": true, "timeZone": "America/Vancouver" }, "created": "2016-10-18T19:02:36.000+0000", "updated": "2016-10-18T19:02:36.000+0000" } ], "maxResults": 1, "total": 1, "startAt": 0 } } }