diff --git a/lib/discovery.js b/lib/discovery.js index 5963f3f1a..3d09e57db 100644 --- a/lib/discovery.js +++ b/lib/discovery.js @@ -186,6 +186,7 @@ function mixinDiscovery(MySQL, mysql) { (table ? ' WHERE table_name=' + mysql.escape(table) : ''), 'table_name, ordinal_position', {}); } + sql += ' ORDER BY ordinal_position'; return sql; }; diff --git a/test/mysql.discover.test.js b/test/mysql.discover.test.js index d2b97c3ea..f1c4fd44b 100644 --- a/test/mysql.discover.test.js +++ b/test/mysql.discover.test.js @@ -126,6 +126,32 @@ describe('Discover models including other users', function() { }); describe('Discover model properties', function() { + describe('Discover model properties in Ordinal Order', function() { + it('should return an array of columns for product in ordinal order', function(done) { + const productProperties = []; + const productPropertiesInOrdinalOrder = [ + 'ID', + 'NAME', + 'AUDIBLE_RANGE', + 'EFFECTIVE_RANGE', + 'ROUNDS', + 'EXTRAS', + 'FIRE_MODES', + ]; + db.discoverModelProperties('PRODUCT', function(err, models) { + if (err) { + console.error(err); + done(err); + } else { + models.forEach(function(m) { productProperties.push(m.columnName); }); + productProperties.forEach((prop, index) => { + assert(productPropertiesInOrdinalOrder[index] === prop); + }); + done(null, models); + } + }); + }); + }); describe('Discover a named model', function() { it('should return an array of columns for product', function(done) { db.discoverModelProperties('product', function(err, models) {