Uploaded image for project: 'Appcelerator - INBOX'
  1. Appcelerator - INBOX
  2. AC-2389

Alloy: Model Fetch by ID does not work on instances (singletons)

    Details

    • Type: Bug
    • Status: Closed
    • Resolution: Invalid
    • Affects Version/s: None
    • Component/s: Alloy
    • Environment:

      Alloy (Master/1.2), Ti 3.1.1GA

      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: <idhere>}

      ) 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

          Activity

            People

            • Assignee:
              shossain Shak Hossain (Inactive)
              Reporter:
              scleaver Sam Cleaver
            • Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Git Integration