Skip to content

Generated Properties

bmeck edited this page Nov 7, 2011 · 2 revisions

Sometimes a property needs to be generated on the fly (for example password salts, expiration times, and creation times). To do so we should use the provided getter and setter schema extensions in Resourceful. For example, to generate a creation time for a document we could use the following:

MyDocumentType.property('created', 'number', {
  get:function () {
    return this.properties.created;
  },
  set:function (val) {
    if(val == null) {
      val = Date.now();
    }
    return this.properties.created = val;
  }
})
Clone this wiki locally