{ "id": "142216", "key": "TIMOB-18308", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": null, "resolutiondate": null, "created": "2015-01-05T10:01:20.000+0000", "priority": null, "labels": [ "SQLite", "adapter", "alloy", "models", "sync" ], "versions": [], "issuelinks": [], "assignee": null, "updated": "2018-02-28T19:55:05.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [], "description": "The Sync method uses model.idAttribute instead of model.config.adapter.idAttribute making fetch with an id go wrong.\r\n\r\nFor example the following model:\r\n\r\n{noformat}\r\nexports.definition = {\r\n config: {\r\n columns: {\r\n \"order_id\": \"INTEGER PRIMARY KEY AUTOINCREMENT\",\r\n \"title\": \"TEXT\",\r\n \"created_at\": \"INTEGER\",\r\n \"price\": \"INTEGER\"\r\n },\r\n adapter: {\r\n type: \"sql\",\r\n collection_name: \"Orders\",\r\n idAttribute : \"order_id\"\r\n }\r\n },\r\n // other keys\r\n}\r\n{noformat}\r\n\r\nNow if we do a fetch on a specifc id:\r\n\r\n{noformat}\r\nvar orders = Alloy.createCollection(\"Order\");\r\n orders.fetch({\r\n id : 2,\r\n success : function() {\r\n console.log(\"OK\");\r\n }\r\n }\r\n);\r\n{noformat}\r\n\r\nWe get an error \"no such column: alloy_id\" because the sync adapter didn't use the model.config.adapter.idAttribute, but model.idAttribute that returned undefined so it used the default alloy id.", "attachment": [], "flagged": false, "summary": "The Sync method of the sqlite adapter doesn't use the idAttribute", "creator": { "name": "michielve", "key": "michielve", "displayName": "Michiel van Eerd", "active": true, "timeZone": "Europe/Berlin" }, "subtasks": [], "reporter": { "name": "michielve", "key": "michielve", "displayName": "Michiel van Eerd", "active": true, "timeZone": "Europe/Berlin" }, "environment": "CLI version 3.4.1 \r\nTitanium SDK version 3.4.1.GA \r\nOS: Mac OS X 10.10.1", "comment": { "comments": [ { "id": "338659", "author": { "name": "michielve", "key": "michielve", "displayName": "Michiel van Eerd", "active": true, "timeZone": "Europe/Berlin" }, "body": "There are 2 things you can do to circumvent this as long as this isn't fixed:\r\n\r\n1) Copy the sql.js sync adapter, rename it, edit it (change \"model.idAttribute\" to \"model.config.adapter.idAttribute\") and use this as your sync adapter.\r\n\r\n2) Add the idAttribute to the object that extends the collection:\r\n\r\n{noformat}\r\nexports.definition = {\r\n config: {\r\n\r\n },\r\n extendCollection: function(Collection) {\r\n _.extend(Collection.prototype, {\r\n idAttribute : \"my_id\"\r\n }\r\n}\r\n{noformat}", "updateAuthor": { "name": "michielve", "key": "michielve", "displayName": "Michiel van Eerd", "active": true, "timeZone": "Europe/Berlin" }, "created": "2015-01-12T11:03:15.000+0000", "updated": "2015-01-12T11:03:15.000+0000" } ], "maxResults": 2, "total": 2, "startAt": 0 } } }