Skip to content

Instantly share code, notes, and snippets.

@greduan
Created March 2, 2016 02:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greduan/a1d90023e86857c0491e to your computer and use it in GitHub Desktop.
Save greduan/a1d90023e86857c0491e to your computer and use it in GitHub Desktop.
var uuid = require('node-uuid')
var M = {}
M.BaseModel = Class(M, 'BaseModel').inherits(Krypton.Model)({
primaryKey: 'uuid',
prototype: {
init: function (config) {
Krypton.Model.prototype.init.call(this, config)
var that = this
this.on('onBeforeCreate', function (next) {
var buffer = new Buffer(16)
uuid.v4(null, buffer)
that.uuid = uuid.unparse(buffer)
return next()
})
},
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment