diff --git a/integration/test/ParseRelationTest.js b/integration/test/ParseRelationTest.js index 32c925739..463ff8313 100644 --- a/integration/test/ParseRelationTest.js +++ b/integration/test/ParseRelationTest.js @@ -43,6 +43,26 @@ describe('Parse Relation', () => { }); }); + it('can do consecutive adds', async () => { + const ChildObject = Parse.Object.extend('ChildObject'); + const childObjects = []; + for (let i = 0; i < 2; i++) { + childObjects.push(new ChildObject({ x: i })); + } + const parent = new Parse.Object('ParentObject'); + await parent.save(); + await Parse.Object.saveAll(childObjects); + for (const child of childObjects) { + parent.relation('child').add(child); + } + await parent.save(); + const results = await parent.relation('child').query().find(); + assert.equal(results.length, 2); + const expectedIds = new Set(childObjects.map(r => r.id)); + const foundIds = new Set(results.map(r => r.id)); + assert.deepEqual(expectedIds, foundIds); + }); + it('can query relation without schema', done => { const ChildObject = Parse.Object.extend('ChildObject'); const childObjects = []; diff --git a/src/ParseRelation.js b/src/ParseRelation.js index 50c8c09f1..7ca22ed4e 100644 --- a/src/ParseRelation.js +++ b/src/ParseRelation.js @@ -50,12 +50,9 @@ class ParseRelation { if (this.parent.id !== parent.id) { throw new Error('Internal Error. Relation retrieved from two different Objects.'); } - } else if (parent.id) { - this.parent = parent; } - } else { - this.parent = parent; } + this.parent = parent; } /**