diff --git a/lib/application.js b/lib/application.js index 2cc69e0e..563f6449 100644 --- a/lib/application.js +++ b/lib/application.js @@ -114,17 +114,27 @@ app.define = function (name, properties, options) { }; ModelCtor.shared = true; - ModelCtor.sharedCtor = function (id, fn) { - if(id) { + ModelCtor.sharedCtor = function (data, id, fn) { + if(typeof data === 'function') { + fn = data; + data = null; + id = null; + } else if (typeof id === 'function') { + fn = id; + id = null; + } + + if(data) { + fn(null, new ModelCtor(data)); + } else if(id) { ModelCtor.find(id, fn); } else { - fn(null, new ModelCtor(data)); + fn(new Error('must specify an id or data')); } }; ModelCtor.sharedCtor.accepts = [ - // todo... models need to expose what id type they need - {arg: 'id', type: 'any'}, - {arg: 'data', type: 'object'} + {arg: 'data', type: 'object'}, + {arg: 'id', type: 'any'} ]; ModelCtor.sharedCtor.http = [ {path: '/'},