[AC-2389] Alloy: Model Fetch by ID does not work on instances (singletons)
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | n/a |
Status | Closed |
Resolution | Invalid |
Resolution Date | 2013-06-24T13:16:39.000+0000 |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Alloy |
Labels | alloy, model, preferences |
Reporter | Sam Cleaver |
Assignee | Shak Hossain |
Created | 2013-06-22T01:50:08.000+0000 |
Updated | 2016-03-08T07:41:25.000+0000 |
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:
Works (returns the object):
var genretest = Alloy.createModel('preferences', {id: "genreversion"});
genretest.fetch();
Doesn't work (returns undefined):
var genretest2 = Alloy.Models.instance('preferences');
genretest2.fetch({id: "genreversion"});
Also doesn't work (something wrong with passing ID via fetch?)
var genretest = Alloy.createModel('preferences');
genretest.fetch({id: "genreversion"});
Obviously 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).
I've attached my preferences.js model to assist in validation.
Attachments
File | Date | Size |
---|---|---|
preferences.js | 2013-06-22T01:50:08.000+0000 | 680 |
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.
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:
Doesn't look like a bug so request closure.