fix id property for composite ids

Signed-off-by: Clark Wang <clark.wangs@gmail.com>
This commit is contained in:
Clark Wang 2015-01-22 10:39:47 +08:00
parent b2f41f4344
commit 2e9e2dd192
2 changed files with 15 additions and 1 deletions

View File

@ -266,7 +266,8 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
get: function () {
var compositeId = {};
var idNames = ModelClass.definition.idNames();
for (var p in idNames) {
for (var i = 0, p; i < idNames.length; i++) {
p = idNames[i];
compositeId[p] = this.__data[p];
}
return compositeId;

View File

@ -243,6 +243,19 @@ describe('ModelBuilder define model', function () {
done(null, User);
});
it('should define an id property for composite ids', function () {
var modelBuilder = new ModelBuilder();
var Follow = modelBuilder.define('Follow', {
followerId: { type: String, id: 1 },
followeeId: { type: String, id: 2 },
followAt: Date
});
var follow = new Follow({ followerId: 1, followeeId: 2 });
follow.should.have.property('id');
assert.deepEqual(follow.id, { followerId: 1, followeeId: 2 });
});
});
describe('DataSource ping', function() {