Model sharedCtor arg handleing

This commit is contained in:
Ritchie Martori 2013-06-07 18:20:24 -07:00
parent 463bc45d3e
commit 087e3eabcb
1 changed files with 16 additions and 6 deletions

View File

@ -114,17 +114,27 @@ app.define = function (name, properties, options) {
}; };
ModelCtor.shared = true; ModelCtor.shared = true;
ModelCtor.sharedCtor = function (id, fn) { ModelCtor.sharedCtor = function (data, id, fn) {
if(id) { 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); ModelCtor.find(id, fn);
} else { } else {
fn(null, new ModelCtor(data)); fn(new Error('must specify an id or data'));
} }
}; };
ModelCtor.sharedCtor.accepts = [ ModelCtor.sharedCtor.accepts = [
// todo... models need to expose what id type they need {arg: 'data', type: 'object'},
{arg: 'id', type: 'any'}, {arg: 'id', type: 'any'}
{arg: 'data', type: 'object'}
]; ];
ModelCtor.sharedCtor.http = [ ModelCtor.sharedCtor.http = [
{path: '/'}, {path: '/'},