From ddd99726beaf6559d8772dd73ec20f90723297b3 Mon Sep 17 00:00:00 2001 From: Kartal Kaan Bozdogan Date: Thu, 23 Nov 2023 14:07:40 +0100 Subject: [PATCH 1/2] Fix #2056 --- integration/test/ParseRelationTest.js | 20 ++++++++++++++++++++ src/ParseRelation.js | 5 +---- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/integration/test/ParseRelationTest.js b/integration/test/ParseRelationTest.js index 32c925739..adec87117 100644 --- a/integration/test/ParseRelationTest.js +++ b/integration/test/ParseRelationTest.js @@ -43,6 +43,26 @@ describe('Parse Relation', () => { }); }); + it('can do consecutive adds (#2056)', 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; } /** From 5dbd5e1d57f3b5b28e3acaba430c7f1a9cdd987b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kartal=20Kaan=20Bozdo=C4=9Fan?= Date: Wed, 29 Nov 2023 14:49:01 +0100 Subject: [PATCH 2/2] Update integration/test/ParseRelationTest.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Manuel <5673677+mtrezza@users.noreply.github.com> Signed-off-by: Kartal Kaan Bozdoğan --- integration/test/ParseRelationTest.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integration/test/ParseRelationTest.js b/integration/test/ParseRelationTest.js index adec87117..463ff8313 100644 --- a/integration/test/ParseRelationTest.js +++ b/integration/test/ParseRelationTest.js @@ -43,7 +43,7 @@ describe('Parse Relation', () => { }); }); - it('can do consecutive adds (#2056)', async () => { + it('can do consecutive adds', async () => { const ChildObject = Parse.Object.extend('ChildObject'); const childObjects = []; for (let i = 0; i < 2; i++) {