[Persistence] Use create from persistence capability

...when an object hasn't been previously persisted. This allows
for compatibility with persistence services which disallow
updates for nonexistent objects (which is not abnomal behavior.)
This commit is contained in:
Victor Woeltjen 2015-08-28 10:46:18 -07:00
parent 5230bdfc6b
commit 620c0415cf

@ -72,7 +72,12 @@ define(
*/
PersistenceCapability.prototype.persist = function () {
var domainObject = this.domainObject,
modified = domainObject.getModel().modified;
model = domainObject.getModel(),
modified = model.modified,
persistenceService = this.persistenceService,
persistenceFn = model.persisted !== undefined ?
this.persistenceService.updateObject :
this.persistenceService.createObject;
// Update persistence timestamp...
domainObject.useCapability("mutation", function (model) {
@ -80,11 +85,11 @@ define(
}, modified);
// ...and persist
return this.persistenceService.updateObject(
return persistenceFn.apply(persistenceService, [
this.getSpace(),
domainObject.getId(),
domainObject.getModel()
);
]);
};
/**