Search code examples
sails.jsjsdata

How do I add properties to a js-data object that I don't want persisted?


I'm using js-data (and js-data-angular) in conjunction with sockets via sails.js. When a new item is created/updated via sockets I want to call attention to it in my ui.

I'd like to add an "updated" property to the object, but don't want to inadvertently persist it to the DB.

Is there a way to hang non-persisting properties on a js-data object?


Solution

  • Yes.

    You can set this globally on the data store or per-resource by using the omit configuration setting. For instance, when instancing your data store, you can instruct JSData to ignore all properties that begin with an underscore:

    var store = new JSData.DS({ omit: [ /^_/ ] });