Add pluralized name to model and remoting method signatures
This commit is contained in:
parent
a690f8d8df
commit
ae9cb9a6f2
|
@ -1,6 +1,8 @@
|
|||
/**
|
||||
* Module dependencies
|
||||
*/
|
||||
|
||||
var i8n = require('inflection');
|
||||
var ModelBaseClass = require('./model.js');
|
||||
// var DataAccessObject = require('./dao.js');
|
||||
var List = require('./list.js');
|
||||
|
@ -109,6 +111,7 @@ Schema.prototype.define = function defineClass(className, properties, settings)
|
|||
|
||||
hiddenProperty(ModelClass, 'schema', schema);
|
||||
hiddenProperty(ModelClass, 'modelName', className);
|
||||
hiddenProperty(ModelClass, 'pluralModelName', i8n.pluralize(className));
|
||||
hiddenProperty(ModelClass, 'relations', {});
|
||||
|
||||
// inherit ModelBaseClass methods
|
||||
|
|
54
lib/dao.js
54
lib/dao.js
|
@ -241,6 +241,10 @@ DataAccessObject.exists = function exists(id, cb) {
|
|||
}
|
||||
};
|
||||
|
||||
// exists ~ remoting attributes
|
||||
DataAccessObject.exists.shared = true;
|
||||
DataAccessObject.exists.accepts = {arg: 'id', type: 'number'};
|
||||
|
||||
/**
|
||||
* Find object by id
|
||||
*
|
||||
|
@ -309,12 +313,13 @@ DataAccessObject.all = function all(params, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
// shared by default
|
||||
// all ~ remoting attributes
|
||||
DataAccessObject.all.accepts = {arg: 'filter', type: 'object'};
|
||||
DataAccessObject.all.shared = true;
|
||||
DataAccessObject.all.http = {
|
||||
|
||||
}
|
||||
DataAccessObject.all.http = [
|
||||
{verb: 'get', path: '/'},
|
||||
{verb: 'get', path: '/all'}
|
||||
];
|
||||
|
||||
/**
|
||||
* Find one record, same as `all`, limited by 1 and return object, not collection
|
||||
|
@ -336,6 +341,18 @@ DataAccessObject.findOne = function findOne(params, cb) {
|
|||
});
|
||||
};
|
||||
|
||||
// findOne ~ remoting attributes
|
||||
DataAccessObject.findOne.accepts = [
|
||||
{arg: 'id', type: 'number', optional: true},
|
||||
{arg: 'filter', type: 'object', optional: true}
|
||||
];
|
||||
DataAccessObject.findOne.shared = true;
|
||||
DataAccessObject.findOne.http = [
|
||||
{verb: 'get', path: '/findOne'},
|
||||
{verb: 'get', path: '/find-one'},
|
||||
{verb: 'get', path: '/:id'}
|
||||
];
|
||||
|
||||
/**
|
||||
* Destroy all records
|
||||
* @param {Function} cb - callback called with (err)
|
||||
|
@ -366,6 +383,14 @@ DataAccessObject.count = function (where, cb) {
|
|||
this.schema.adapter.count(this.modelName, cb, where);
|
||||
};
|
||||
|
||||
|
||||
// count ~ remoting attributes
|
||||
DataAccessObject.count.shared = true;
|
||||
DataAccessObject.count.accepts = [
|
||||
{arg: 'where', type: 'object', optional: true}
|
||||
];
|
||||
DataAccessObject.count.http = {verb: 'get', path: '/count'};
|
||||
|
||||
/**
|
||||
* Save instance. When instance haven't id, create method called instead.
|
||||
* Triggers: validate, save, update | create
|
||||
|
@ -437,6 +462,14 @@ DataAccessObject.prototype.save = function (options, callback) {
|
|||
}
|
||||
};
|
||||
|
||||
// save ~ remoting attributes
|
||||
DataAccessObject.prototype.save.shared = true;
|
||||
DataAccessObject.prototype.save.returns = {arg: 'obj', type: 'object'};
|
||||
DataAccessObject.prototype.save.http = [
|
||||
{verb: 'post', path: '/'},
|
||||
{verb: 'put', path: '/:id'}
|
||||
];
|
||||
|
||||
DataAccessObject.prototype.isNewRecord = function () {
|
||||
return !this.id;
|
||||
};
|
||||
|
@ -470,6 +503,12 @@ DataAccessObject.prototype.destroy = function (cb) {
|
|||
});
|
||||
};
|
||||
|
||||
// destroy ~ remoting attributes
|
||||
DataAccessObject.prototype.destroy.shared = true;
|
||||
DataAccessObject.prototype.destroy.http = [
|
||||
{verb: 'del', path: '/'}
|
||||
];
|
||||
|
||||
/**
|
||||
* Update single attribute
|
||||
*
|
||||
|
@ -546,6 +585,12 @@ DataAccessObject.prototype.updateAttributes = function updateAttributes(data, cb
|
|||
}, data);
|
||||
};
|
||||
|
||||
// updateAttributes ~ remoting attributes
|
||||
DataAccessObject.prototype.updateAttributes.shared = true;
|
||||
DataAccessObject.prototype.updateAttributes.accepts = {arg: 'data', type: 'object'};
|
||||
DataAccessObject.prototype.updateAttributes.http = [
|
||||
{verb: 'put', path: '/'}
|
||||
];
|
||||
|
||||
/**
|
||||
* Reload object from persistence
|
||||
|
@ -559,7 +604,6 @@ DataAccessObject.prototype.reload = function reload(callback) {
|
|||
this.constructor.find(this.id, callback);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Define readonly property on object
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue