{ "id": "110649", "key": "ALOY-542", "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": [ { "id": "15271", "description": "Alloy 1.1.0, concurrent with SDK 3.1.0", "name": "Alloy 1.1.0", "archived": false, "released": true, "releaseDate": "2013-04-16" }, { "id": "14875", "description": "2013 Sprint 06", "name": "2013 Sprint 06", "archived": true, "released": true, "releaseDate": "2013-03-25" } ], "resolution": { "id": "1", "description": "A fix for this issue is checked into the tree and tested.", "name": "Fixed" }, "resolutiondate": "2013-03-15T22:05:15.000+0000", "created": "2013-03-05T21:00:50.000+0000", "priority": { "name": "High", "id": "2" }, "labels": [ "alloy", "ios", "model", "sqlite" ], "versions": [ { "id": "14634", "description": "Alloy 1.0.0", "name": "Alloy 1.0.0", "archived": false, "released": true, "releaseDate": "2013-02-19" } ], "issuelinks": [], "assignee": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2013-03-26T01:07:53.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": "12332", "name": "Titanium SDK", "description": "Any integration or issues with the TiSDK" } ], "description": "The example of idAttribute in the alloy test examples (sql_keywords) works, but when setting idAttribute to a model attribute that is of type text it won't persist the data. \r\n\r\nExample app attached. ", "attachment": [ { "id": "35927", "filename": "app.zip", "author": { "name": "dwelch", "key": "dwelch", "displayName": "David Welch", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-03-05T21:00:50.000+0000", "size": 5766452, "mimeType": "application/zip" } ], "flagged": false, "summary": "idAttribute set to a model attribute that is of type text not persisting", "creator": { "name": "dwelch", "key": "dwelch", "displayName": "David Welch", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "dwelch", "key": "dwelch", "displayName": "David Welch", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "TiMobile SDK 3.0.2.GA\r\nAlloy 1.0.0", "comment": { "comments": [ { "id": "240793", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Did you try this on a fresh project, or did you change the idAttribute after the SQLite database had already been built?", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-03-05T21:27:05.000+0000", "updated": "2013-03-05T21:27:05.000+0000" }, { "id": "240796", "author": { "name": "dwelch", "key": "dwelch", "displayName": "David Welch", "active": true, "timeZone": "America/Los_Angeles" }, "body": "I tried this on a fresh project. After it didn't work I deleted the app and tried it without idAttribute where it worked. ", "updateAuthor": { "name": "dwelch", "key": "dwelch", "displayName": "David Welch", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-03-05T21:30:34.000+0000", "updated": "2013-03-05T21:30:34.000+0000" }, { "id": "240797", "author": { "name": "dwelch", "key": "dwelch", "displayName": "David Welch", "active": true, "timeZone": "America/Los_Angeles" }, "body": "It should be noted that it only works when artist_id is \"integer PRIMARY KEY AUTOINCREMENT\". If it's \"integer PRIMARY KEY\" or \"text\" the data won't persist. I delete the database each time to start fresh.", "updateAuthor": { "name": "dwelch", "key": "dwelch", "displayName": "David Welch", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-03-05T21:34:38.000+0000", "updated": "2013-03-05T21:34:38.000+0000" }, { "id": "240798", "author": { "name": "dwelch", "key": "dwelch", "displayName": "David Welch", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Clearly, when I set artist_id to \"integer PRIMARY KEY AUTOINCREMENT\" or \"integer PRIMARY KEY\" I change my code in index.js to set it to an integer instead of string. ", "updateAuthor": { "name": "dwelch", "key": "dwelch", "displayName": "David Welch", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-03-05T21:36:13.000+0000", "updated": "2013-03-05T21:36:13.000+0000" }, { "id": "240800", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "That's weird since the default behavior in the absence of the idAttribute is for alloy to create one itself, a GUID that is a TEXT field named \"alloy_id\". I'll have to dig into your sample to see why it's not working in your case.", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-03-05T21:44:39.000+0000", "updated": "2013-03-05T21:44:39.000+0000" }, { "id": "240802", "author": { "name": "dwelch", "key": "dwelch", "displayName": "David Welch", "active": true, "timeZone": "America/Los_Angeles" }, "body": "I thought so as well since alloy_id is text. Either way I wasn't able to persist the data.", "updateAuthor": { "name": "dwelch", "key": "dwelch", "displayName": "David Welch", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-03-05T21:46:32.000+0000", "updated": "2013-03-05T21:46:32.000+0000" }, { "id": "241528", "author": { "name": "rococo", "key": "rococo", "displayName": "Kaos Arts", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Ran into this bug too. \r\n\r\n// idAttribute = \"email\"\r\n\r\n// This silently fails to save\r\nvar userM = Alloy.createModel('userModel', {email: userEmail, name: \"Test\"});\r\nuserM.save();\r\n\r\n// This works\r\nvar userM = Alloy.createModel('userModel', {email: userEmail, name: \"Test\"});\r\nuserM.id = null;\r\nuserM.save();\r\n\r\nLooks like the root cause of this bug is that when idAttribute value is set the model.id is also assigned immediately, before its saved. Too soon. That causes backbone's isNew() to return false at save, and attempt an update instead of a create. Which then silently fails obviously (it'll even call the success function if you set one!) A hack-around is to set model.id = null after createModel() but before save().\r\n", "updateAuthor": { "name": "rococo", "key": "rococo", "displayName": "Kaos Arts", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-03-11T03:04:11.000+0000", "updated": "2013-03-11T03:06:56.000+0000" }, { "id": "242066", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "I found the same Kimberlee, apologies for not logging it here earlier to save the time of others investigating. I'm working on this one now.", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-03-13T20:04:00.000+0000", "updated": "2013-03-13T20:04:00.000+0000" }, { "id": "242536", "author": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "body": "This turned out to be a lot more complicated than expected initially. Mainly because the resolution to this issue involved changing the way the sql adapter inserts and updates, which is now based on DB constraints. This in turn changed the properties of the default alloy_id field used for automatically assigning unique ids to models, which had implications on adding alloy_id to existing databases, particularly preloaded ones. Details of all this are covered in this commit (props to Aaron Saunders for the initial code for these changes): https://github.com/appcelerator/alloy/commit/d511ebd64b5b1e8f840d1be80b90f0639d251e87\r\n\r\nIn addition, the core issue of this ticket can be seen addressed in the following test app: https://github.com/appcelerator/alloy/tree/master/test/apps/models/sql_idAttribute", "updateAuthor": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2013-03-15T22:05:15.000+0000", "updated": "2013-03-15T22:07:52.000+0000" } ], "maxResults": 11, "total": 11, "startAt": 0 } } }