Skip to content

fix: Calling Parse.Object.relation.add multiple times on an on object does not work #2057

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions integration/test/ParseRelationTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down
5 changes: 1 addition & 4 deletions src/ParseRelation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know what as the purpose of this parent.id check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really. My educated guess is that it checks if the parent has been saved.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we'd need to understand this logic better and the purpose of the parent.id check before we remove it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. Unfortunately my team doesn't have the capacity for that, but we'd be more than happy to review/discuss any findings in this direction.

this.parent = parent;
}
} else {
this.parent = parent;
}
this.parent = parent;
}

/**
Expand Down