Alias destroy/destroyAll

This commit is contained in:
Raymond Feng 2013-06-25 20:36:00 -07:00
parent 6cb53e5001
commit 0ae61d3b53
1 changed files with 4 additions and 8 deletions

View File

@ -201,12 +201,8 @@ BaseSQL.prototype.exists = function (model, id, callback) {
}; };
BaseSQL.prototype.find = function find(model, id, callback) { BaseSQL.prototype.find = function find(model, id, callback) {
var idNumber = Number(id);
if (isNaN(idNumber)) {
callback(new Error('id is not a number'));
}
var sql = 'SELECT * FROM ' + var sql = 'SELECT * FROM ' +
this.tableEscaped(model) + ' WHERE ' + this.idColumnEscaped(model) + ' = ' + idNumber + ' LIMIT 1'; this.tableEscaped(model) + ' WHERE ' + this.idColumnEscaped(model) + ' = ' + id + ' LIMIT 1';
this.query(sql, function (err, data) { this.query(sql, function (err, data) {
if (data && data.length === 1) { if (data && data.length === 1) {
@ -218,16 +214,16 @@ BaseSQL.prototype.find = function find(model, id, callback) {
}.bind(this)); }.bind(this));
}; };
BaseSQL.prototype.destroy = function destroy(model, id, callback) { BaseSQL.prototype.delete = BaseSQL.prototype.destroy = function destroy(model, id, callback) {
var sql = 'DELETE FROM ' + var sql = 'DELETE FROM ' +
this.tableEscaped(model) + ' WHERE ' + this.escapeName('id') + ' = ' + Number(id); this.tableEscaped(model) + ' WHERE ' + this.idColumnEscaped(model) + ' = ' + id;
this.command(sql, function (err) { this.command(sql, function (err) {
callback(err); callback(err);
}); });
}; };
BaseSQL.prototype.destroyAll = function destroyAll(model, callback) { BaseSQL.prototype.deleteAll = BaseSQL.prototype.destroyAll = function destroyAll(model, callback) {
this.command('DELETE FROM ' + this.tableEscaped(model), function (err) { this.command('DELETE FROM ' + this.tableEscaped(model), function (err) {
if (err) { if (err) {
return callback(err, []); return callback(err, []);