Skip to content

Commit cdf35c5

Browse files
committed
fix: add order by ordinal position for query columns
Signed-off-by: Muhammad Aaqil <aaqilcs102@gmail.com>
1 parent 21e3bba commit cdf35c5

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

lib/discovery.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ function mixinDiscovery(MySQL, mysql) {
186186
(table ? ' WHERE table_name=' + mysql.escape(table) : ''),
187187
'table_name, ordinal_position', {});
188188
}
189+
sql += ' ORDER BY ordinal_position';
189190
return sql;
190191
};
191192

test/mysql.discover.test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,32 @@ describe('Discover models including other users', function() {
125125
});
126126

127127
describe('Discover model properties', function() {
128+
describe('Discover model properties in Ordinal Order', function() {
129+
it('should return an array of columns for product in ordinal order', function(done) {
130+
const productProperties = [];
131+
const productPropertiesInOrdinalOrder = [
132+
'ID',
133+
'NAME',
134+
'AUDIBLE_RANGE',
135+
'EFFECTIVE_RANGE',
136+
'ROUNDS',
137+
'EXTRAS',
138+
'FIRE_MODES',
139+
];
140+
db.discoverModelProperties('PRODUCT', function(err, models) {
141+
if (err) {
142+
console.error(err);
143+
done(err);
144+
} else {
145+
models.forEach(function(m) { productProperties.push(m.columnName); });
146+
productProperties.forEach((prop, index) => {
147+
assert(productPropertiesInOrdinalOrder[index] === prop);
148+
});
149+
done(null, models);
150+
}
151+
});
152+
});
153+
});
128154
describe('Discover a named model', function() {
129155
it('should return an array of columns for product', function(done) {
130156
db.discoverModelProperties('product', function(err, models) {

0 commit comments

Comments
 (0)