diff --git a/lib/couchdb.js b/lib/couchdb.js index 58be45d..9d632f7 100644 --- a/lib/couchdb.js +++ b/lib/couchdb.js @@ -720,7 +720,7 @@ CouchDB.prototype.replaceById = function(model, id, data, options, cb) { */ CouchDB.prototype.selectModel = function(model, migrate) { var self = this; - var dbName, db, mo; + var dbName, db, mo, partitionKey; var modelView = null; var modelSelector = null; var dateFields = []; @@ -747,20 +747,27 @@ CouchDB.prototype.selectModel = function(model, migrate) { } for (var p in mo.properties) { - if (mo.properties[p].type.name === 'Date') { + debug('visiting model property %s', p); + if (mo.properties[p].type && mo.properties[p].type.name === 'Date') { dateFields.push(p); } + if (mo.properties[p].isPartitionKey) { + partitionKey = p; + debug('partition key name %s', partitionKey); + } } + var idName = this.idName(model); debug('CouchDB.prototype.selectModel use %j', dbName); this.pool[model] = { - mo: mo, + dateFields: dateFields, db: self.getDriverInst().use(dbName), + dbName: dbName, idName: idName, - modelView: modelView, + mo: mo, modelSelector: modelSelector, - dateFields: dateFields, - dbName: dbName, + modelView: modelView, + partitionKey: partitionKey, }; // nano doesn't have api 'find' while nodejs-cloudant has