Merge pull request #405 from clarkorz/fix/id-for-compositeIds
fix id property for composite ids
This commit is contained in:
commit
bba1ce0768
|
@ -267,7 +267,8 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
|
||||||
get: function () {
|
get: function () {
|
||||||
var compositeId = {};
|
var compositeId = {};
|
||||||
var idNames = ModelClass.definition.idNames();
|
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];
|
compositeId[p] = this.__data[p];
|
||||||
}
|
}
|
||||||
return compositeId;
|
return compositeId;
|
||||||
|
|
|
@ -243,6 +243,19 @@ describe('ModelBuilder define model', function () {
|
||||||
done(null, User);
|
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() {
|
describe('DataSource ping', function() {
|
||||||
|
|
Loading…
Reference in New Issue