Skip to content

Commit ddd9972

Browse files
committed
Fix #2056
1 parent fea8edf commit ddd9972

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

integration/test/ParseRelationTest.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,26 @@ describe('Parse Relation', () => {
4343
});
4444
});
4545

46+
it('can do consecutive adds (#2056)', async () => {
47+
const ChildObject = Parse.Object.extend('ChildObject');
48+
const childObjects = [];
49+
for (let i = 0; i < 2; i++) {
50+
childObjects.push(new ChildObject({ x: i }));
51+
}
52+
const parent = new Parse.Object('ParentObject');
53+
await parent.save();
54+
await Parse.Object.saveAll(childObjects);
55+
for (const child of childObjects) {
56+
parent.relation('child').add(child);
57+
}
58+
await parent.save();
59+
const results = await parent.relation('child').query().find();
60+
assert.equal(results.length, 2);
61+
const expectedIds = new Set(childObjects.map(r => r.id));
62+
const foundIds = new Set(results.map(r => r.id));
63+
assert.deepEqual(expectedIds, foundIds);
64+
});
65+
4666
it('can query relation without schema', done => {
4767
const ChildObject = Parse.Object.extend('ChildObject');
4868
const childObjects = [];

src/ParseRelation.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,9 @@ class ParseRelation {
5050
if (this.parent.id !== parent.id) {
5151
throw new Error('Internal Error. Relation retrieved from two different Objects.');
5252
}
53-
} else if (parent.id) {
54-
this.parent = parent;
5553
}
56-
} else {
57-
this.parent = parent;
5854
}
55+
this.parent = parent;
5956
}
6057

6158
/**

0 commit comments

Comments
 (0)