Merge pull request #405 from clarkorz/fix/id-for-compositeIds

fix id property for composite ids
This commit is contained in:
Raymond Feng 2015-02-02 08:59:40 -08:00
commit bba1ce0768
2 changed files with 15 additions and 1 deletions

View File

@ -267,7 +267,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() {