diff --git a/lib/mysql.js b/lib/mysql.js index 3400e53..1fe3d1b 100644 --- a/lib/mysql.js +++ b/lib/mysql.js @@ -31,9 +31,7 @@ exports.initialize = function initializeDataSource(dataSource, callback) { s.supportBigNumbers = (s.supportBigNumbers || false); s.timezone = (s.timezone || 'local'); - if(isNaN(s.connectionLimit)) { - s.connectionLimit = s.connectionLimit; - } else { + if(!isNaN(s.connectionLimit)) { s.connectionLimit = 10; } @@ -473,7 +471,7 @@ MySQL.prototype.all = function all(model, filter, callback) { if (!filter.order) { var idNames = this.idNames(model); if (idNames && idNames.length) { - filter.order = idNames.join(' '); + filter.order = idNames; } } diff --git a/test/mysql.discover.test.js b/test/mysql.discover.test.js index b39b983..0e0125b 100644 --- a/test/mysql.discover.test.js +++ b/test/mysql.discover.test.js @@ -7,6 +7,7 @@ var db; before(function() { var config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql; + config.database = 'STRONGLOOP'; db = new DataSource(require('../'), config); }); @@ -192,3 +193,28 @@ describe('Discover LDL schema from a table', function () { }); }); }); + +describe('Discover and build models', function () { + it('should discover and build models', function (done) { + db.discoverAndBuildModels('INVENTORY', {owner: 'STRONGLOOP', visited: {}, associations: true}, function (err, models) { + assert(models.Inventory, 'Inventory model should be discovered and built'); + var schema = models.Inventory.definition; + assert(schema.settings.mysql.schema === 'STRONGLOOP'); + assert(schema.settings.mysql.table === 'INVENTORY'); + assert(schema.properties.productId); + assert(schema.properties.productId.type === String); + assert(schema.properties.productId.mysql.columnName === 'PRODUCT_ID'); + assert(schema.properties.locationId); + assert(schema.properties.locationId.type === String); + assert(schema.properties.locationId.mysql.columnName === 'LOCATION_ID'); + assert(schema.properties.available); + assert(schema.properties.available.type === Number); + assert(schema.properties.total); + assert(schema.properties.total.type === Number); + models.Inventory.findOne(function (err, inv) { + assert(!err, 'error should not be reported'); + done(); + }); + }); + }); +});