Skip to content

Calling .add multiple times on relations is broken #2056

Closed
@mstniy

Description

@mstniy

New Issue Checklist

Issue Description

Calling .add multiple times on a relation adds only the object mentioned in the first call.

Steps to reproduce

it('can do consecutive adds', done => {
    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');
    parent.save().then(parentAgain => {
      Parse.Object.saveAll(childObjects)
        .then(() => {
          for (const child of childObjects) {
            parentAgain.relation('child').add(child);
          }
          return parentAgain.save();
        })
        .then(() => {
          return parentAgain.relation('child').query().find();
        })
        .then(results => {
          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);
          done();
        });
    });
  });

Actual Outcome

Only the first child object is added to the relation

Expected Outcome

Both of the child objects should be added to the relation

Environment

Server

  • Parse Server version: alpha
  • Operating system: Ubuntu
  • Local or remote host (AWS, Azure, Google Cloud, Heroku, Digital Ocean, etc): local

Database

  • System (MongoDB or Postgres): MongoDB
  • Database version: 6.0.11
  • Local or remote host (MongoDB Atlas, mLab, AWS, Azure, Google Cloud, etc): local

Client

  • Parse JS SDK version: alpha

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    state:releasedReleased as stable versionstate:released-alphaReleased as alpha versionstate:released-betaReleased as beta versiontype:bugImpaired feature or lacking behavior that is likely assumed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions