Skip to content

Instantly share code, notes, and snippets.

@gaboelnuevo
Created September 13, 2015 23:35
Show Gist options
  • Save gaboelnuevo/35ed9e96e8194b103fad to your computer and use it in GitHub Desktop.
Save gaboelnuevo/35ed9e96e8194b103fad to your computer and use it in GitHub Desktop.
loopback: Model filtered properties
var FILTERED_PROPERTIES = ['createdAt', 'updatedAt'];
Model.observe('before save', function filterProperties(ctx, next) {
if (ctx.options && ctx.options.skipPropertyFilter) return next();
if (ctx.instance) {
FILTERED_PROPERTIES.forEach(function(p) { ctx.instance.unsetAttribute(p); });
} else {
FILTERED_PROPERTIES.forEach(function(p) { delete ctx.data[p]; });
}
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment