fix id properties should sort by its index
Signed-off-by: Clark Wang <clark.wangs@gmail.com>
This commit is contained in:
parent
0af69794a3
commit
c37de7f008
|
@ -141,7 +141,7 @@ ModelDefinition.prototype.ids = function () {
|
||||||
ids.push({name: key, id: id, property: props[key]});
|
ids.push({name: key, id: id, property: props[key]});
|
||||||
}
|
}
|
||||||
ids.sort(function (a, b) {
|
ids.sort(function (a, b) {
|
||||||
return a.key - b.key;
|
return a.id - b.id;
|
||||||
});
|
});
|
||||||
this._ids = ids;
|
this._ids = ids;
|
||||||
return ids;
|
return ids;
|
||||||
|
|
|
@ -215,6 +215,28 @@ describe('ModelDefinition class', function () {
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should sort id properties by its index', function () {
|
||||||
|
var modelBuilder = new ModelBuilder();
|
||||||
|
|
||||||
|
var User = new ModelDefinition(modelBuilder, 'User', {
|
||||||
|
userId: {type: String, id: 2},
|
||||||
|
userType: {type: String, id: 1},
|
||||||
|
name: "string",
|
||||||
|
bio: ModelBuilder.Text,
|
||||||
|
approved: Boolean,
|
||||||
|
joinedAt: Date,
|
||||||
|
age: "number"
|
||||||
|
});
|
||||||
|
|
||||||
|
var ids = User.ids();
|
||||||
|
assert.ok(Array.isArray(ids));
|
||||||
|
assert.equal(ids.length, 2);
|
||||||
|
assert.equal(ids[0].id, 1);
|
||||||
|
assert.equal(ids[0].name, 'userType');
|
||||||
|
assert.equal(ids[1].id, 2);
|
||||||
|
assert.equal(ids[1].name, 'userId');
|
||||||
|
});
|
||||||
|
|
||||||
it('should report correct table/column names', function (done) {
|
it('should report correct table/column names', function (done) {
|
||||||
var modelBuilder = new ModelBuilder();
|
var modelBuilder = new ModelBuilder();
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue