{ "id": "116361", "key": "AC-2389", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "12217", "key": "AC", "name": "Appcelerator - INBOX", "projectCategory": { "id": "10000", "description": "", "name": "Customer Service" } }, "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2013-06-24T13:16:39.000+0000", "created": "2013-06-22T01:50:08.000+0000", "labels": [ "alloy", "model", "preferences" ], "versions": [], "issuelinks": [], "assignee": { "name": "shossain", "key": "shossain", "displayName": "Shak Hossain", "active": false, "timeZone": "America/Los_Angeles" }, "updated": "2016-03-08T07:41:25.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": "14544", "name": "Alloy", "description": "Please enter tickets related to the Alloy here." } ], "description": "I have a preferences model which stores app preferences/settings; it uses the preferences sync adapter for this purpose. However when attempting to retrieve a result using the fetch({id: }) method, undefined is always returned. This makes the use of instances (singletons) impossible, the workaround is to use an instance of a Model initiated with the ID desired. For example:\r\n\r\nWorks (returns the object):\r\n{code:javascript} \r\nvar genretest = Alloy.createModel('preferences', {id: \"genreversion\"});\r\ngenretest.fetch();\r\n{code}\r\n\r\nDoesn't work (returns undefined):\r\n{code:javascript} \r\nvar genretest2 = Alloy.Models.instance('preferences');\r\ngenretest2.fetch({id: \"genreversion\"});\r\n{code}\r\nAlso doesn't work (something wrong with passing ID via fetch?)\r\n{code:javascript} \r\nvar genretest = Alloy.createModel('preferences');\r\ngenretest.fetch({id: \"genreversion\"});\r\n{code}\r\n\r\nObviously this is a performance issue as it means that singletons cannot be used throughout the app if a specific ID is desired (unless I've misinterpreted something).\r\n\r\nI've attached my preferences.js model to assist in validation.", "attachment": [ { "id": "40167", "filename": "preferences.js", "author": { "name": "scleaver", "key": "scleaver", "displayName": "Sam Cleaver", "active": true, "timeZone": "Europe/London" }, "created": "2013-06-22T01:50:08.000+0000", "size": 680, "mimeType": "application/javascript" } ], "flagged": false, "summary": "Alloy: Model Fetch by ID does not work on instances (singletons)", "creator": { "name": "scleaver", "key": "scleaver", "displayName": "Sam Cleaver", "active": true, "timeZone": "Europe/London" }, "subtasks": [], "reporter": { "name": "scleaver", "key": "scleaver", "displayName": "Sam Cleaver", "active": true, "timeZone": "Europe/London" }, "environment": "Alloy (Master/1.2), Ti 3.1.1GA", "comment": { "comments": [ { "id": "259111", "author": { "name": "scleaver", "key": "scleaver", "displayName": "Sam Cleaver", "active": true, "timeZone": "Europe/London" }, "body": "Through some preliminary testing modifying the Alloy source it seems that if the ID is passed through the fetch method, it is given/not given to the sync method as undefined. This is likely the reason for the issue though according to the documentation an object containing an id should be able to be passed to the fetch method. Most certainly I'm unsure as to how a singleton can be effectively used without being able to pass an object containing id through the fetch method.", "updateAuthor": { "name": "scleaver", "key": "scleaver", "displayName": "Sam Cleaver", "active": true, "timeZone": "Europe/London" }, "created": "2013-06-22T01:53:58.000+0000", "updated": "2013-06-22T01:53:58.000+0000" }, { "id": "259151", "author": { "name": "scleaver", "key": "scleaver", "displayName": "Sam Cleaver", "active": true, "timeZone": "Europe/London" }, "body": "After reading through some Backbone documentation it seems you can retrieve results using the .get method (as opposed to fetch). I was confused by the Sync Adapters guide in the documentation as it shows an example whereby a Model is retrieved using the fetch method:\n\n{code:javascript}\n// Performs a GET on /library/1\nbook.fetch({id:1}); \n{code}\n\nDoesn't look like a bug so request closure.", "updateAuthor": { "name": "scleaver", "key": "scleaver", "displayName": "Sam Cleaver", "active": true, "timeZone": "Europe/London" }, "created": "2013-06-24T11:30:52.000+0000", "updated": "2013-06-24T11:30:52.000+0000" } ], "maxResults": 2, "total": 2, "startAt": 0 } } }