Jslinize if blocks, not strict equal for ids on uniqueness checking

This commit is contained in:
Anatoliy Chakkaev 2012-04-19 03:20:44 +04:00
parent 221c3d4c83
commit 1b83266fd6
7 changed files with 34 additions and 13 deletions

View File

@ -18,3 +18,4 @@ try {
exports.version = require('../package').version;
}
} catch (e) {}

View File

@ -67,7 +67,9 @@ MongooseAdapter.prototype.getCached = function (model, id, cb) {
cb(null, this.cache[model][id]);
} else {
this._models[model].findById(id, function (err, instance) {
if (err) return cb(err);
if (err) {
return cb(err);
}
this.cache[model][id] = instance;
cb(null, instance);
}.bind(this));
@ -83,7 +85,9 @@ MongooseAdapter.prototype.create = function (model, data, callback) {
MongooseAdapter.prototype.save = function (model, data, callback) {
this.getCached(model, data.id, function (err, inst) {
if (err) return callback(err);
if (err) {
return callback(err);
}
merge(inst, data);
inst.save(callback);
});
@ -92,7 +96,9 @@ MongooseAdapter.prototype.save = function (model, data, callback) {
MongooseAdapter.prototype.exists = function (model, id, callback) {
delete this.cache[model][id];
this.getCached(model, id, function (err, data) {
if (err) return callback(err);
if (err) {
return callback(err);
}
callback(err, !!data);
});
};
@ -100,16 +106,23 @@ MongooseAdapter.prototype.exists = function (model, id, callback) {
MongooseAdapter.prototype.find = function find(model, id, callback) {
delete this.cache[model][id];
this.getCached(model, id, function (err, data) {
if (err) return callback(err);
if (err) {
return callback(err);
}
callback(err, data ? data.toObject() : null);
});
};
MongooseAdapter.prototype.destroy = function destroy(model, id, callback) {
this.getCached(model, id, function (err, data) {
if (err) return callback(err);
if (data) data.remove(callback);
else callback(null);
if (err) {
return callback(err);
}
if (data) {
data.remove(callback);
} else {
callback(null);
}
});
};

View File

@ -196,7 +196,7 @@ PG.prototype.fromDatabase = function (model, data) {
};
PG.prototype.escapeName = function (name) {
return '"' + name + '"';
return '"' + name.replace(/\./g, '"."') + '"';
};
PG.prototype.all = function all(model, filter, callback) {

View File

@ -38,8 +38,11 @@ Hookable.prototype.trigger = function trigger(actionName, work, data) {
}
function next(done) {
if (afterHook) afterHook.call(inst, done);
else if (done) done.call(this);
if (afterHook) {
afterHook.call(inst, done);
} else if (done) {
done.call(this);
}
}
};

View File

@ -257,7 +257,7 @@ function validateUniqueness(attr, conf, err, done) {
this.constructor.all(cond, function (error, found) {
if (found.length > 1) {
err();
} else if (found.length === 1 && found[0].id !== this.id) {
} else if (found.length === 1 && found[0].id != this.id) {
err();
}
done();

View File

@ -1,8 +1,8 @@
require('./spec_helper').init(exports);
var Schema = require('../index').Schema;
var Text = Schema.Text;
require('./spec_helper').init(exports);
var schemas = {
// riak: {},
mysql: {

View File

@ -1,3 +1,7 @@
var semicov = require('semicov');
semicov.init('lib');
process.on('exit', semicov.report);
try {
global.sinon = require('sinon');
} catch (e) {