Simplify the id lookup

This commit is contained in:
Raymond Feng 2014-09-04 09:32:38 -07:00
parent 5c7a9aee3a
commit 057d39d5bb
1 changed files with 3 additions and 6 deletions

View File

@ -39,15 +39,12 @@ function DataAccessObject() {
} }
} }
function idName(m) { function idName(m) {
return m.getDataSource().idName return m.definition.idName() || 'id';
? m.getDataSource().idName(m.modelName) : 'id';
} }
function getIdValue(m, data) { function getIdValue(m, data) {
return data && data[m.getDataSource().idName(m.modelName)]; return data && data[idName(m)];
} }
function setIdValue(m, data, value) { function setIdValue(m, data, value) {
@ -330,7 +327,7 @@ DataAccessObject.findByIds = function(ids, cond, cb) {
cond = {}; cond = {};
} }
var pk = this.dataSource.idName(this.modelName) || 'id'; var pk = idName(this);
if (ids.length === 0) { if (ids.length === 0) {
process.nextTick(function() { cb(null, []); }); process.nextTick(function() { cb(null, []); });
return; return;