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.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: '/'},