Skip to content

Commit 52d8854

Browse files
committed
Fix #2056
1 parent fea8edf commit 52d8854

File tree

2 files changed

+29
-4
lines changed

2 files changed

+29
-4
lines changed

integration/test/ParseRelationTest.js

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

46+
it('can do consecutive adds (#2056)', done => {
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+
parent.save().then(parentAgain => {
54+
Parse.Object.saveAll(childObjects)
55+
.then(() => {
56+
for (const child of childObjects) {
57+
parentAgain.relation('child').add(child);
58+
}
59+
return parentAgain.save();
60+
})
61+
.then(() => {
62+
return parentAgain.relation('child').query().find();
63+
})
64+
.then(results => {
65+
assert.equal(results.length, 2);
66+
const expectedIds = new Set(childObjects.map(r => r.id));
67+
const foundIds = new Set(results.map(r => r.id));
68+
assert.deepEqual(expectedIds, foundIds);
69+
done();
70+
});
71+
});
72+
});
73+
4674
it('can query relation without schema', done => {
4775
const ChildObject = Parse.Object.extend('ChildObject');
4876
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)