Merge pull request #402 from clarkorz/fix/ids-sort

fix id properties should sort by its index
This commit is contained in:
Raymond Feng 2015-01-21 08:29:07 -08:00
commit b2f41f4344
2 changed files with 23 additions and 1 deletions

View File

@ -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;

View File

@ -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();