Skip to content

Instantly share code, notes, and snippets.

@dbaba
Last active October 7, 2015 09:27
Show Gist options
  • Save dbaba/3143058 to your computer and use it in GitHub Desktop.
Save dbaba/3143058 to your computer and use it in GitHub Desktop.
ModelMapper.updateFields() for Singleton Models from MOAT js API Document
// Prepares an update operation.
var mySingletonTypeMapper =
session.newModelMapperStub('MySingletonType');
// Creates or retrieves a model object
var obj = ...;
obj.myProperty = 'myValue';
obj.myIntProperty = 12345;
obj.myBooleanProperty = true;
// Enqueues the update operation
mySingletonTypeMapper.updateFields(obj,
// Specifies 2 of 3 props to be updated
['myProperty', 'myIntProperty'], {
error : function(type, code) { // ---- (2)
if (type == 'NOT_FOUND') {
// Create new!
mySingletonTypeMapper.add(obj);
session.commit();
}
}
});
// Commits all preset requests
session.commit(); // ---- (1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment