From 087e3eabcb7bcea12233ccc3ee7527f553de4c76 Mon Sep 17 00:00:00 2001 From: Ritchie Martori Date: Fri, 7 Jun 2013 18:20:24 -0700 Subject: [PATCH] Model sharedCtor arg handleing --- lib/application.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) 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: '/'},