Skip to content

Release 1.1.0 Changes

Paul Mietz Egli edited this page Aug 26, 2014 · 1 revision

In release 1.1.0, we have made some changes to the Alloy sync adapter which should make it much easier to define and use views. Views are now defined as a dictionary instead of an array, and each view can have its own set of predefined query options. Example:

  config: {
    adapter: {
      type: "titouchdb",
      dbname: "clients",
      views: {
        "client_by_lastname": {
          map: function(doc) {
            if (doc.modelname === 'client') {
              emit([doc.last, doc.first], null);
            }
          }
        },
        "client_by_created": {
          map: function(doc) {
            if (doc.modelname === 'client') {
              emit(doc.created, null);
            }
          },
          // options that apply only to this view
          query_options: {
            descending: true
          }
        }
      },
      // options that apply to all views
      default_query_options: {
        prefetch: true
      },
      modelname: 'client'
    }
  },

The config.adapter.default_query_options set properties on the Query object used to run the views and apply to all views defined in the model file. In version 1.1.0, you can also define a config.adapter.views.<viewname>.query_options to define options that apply for a particular view. These options override anything in default_query_options. Both of these properties can also be overridden when calling fetch; for example, to get a list of clients by creation date in ascending order:

clients.fetch({ view: 'client_by_created', descending: false });
Clone this wiki locally