Skip to content

[bug] Fix increment bug for nested array object field #1343

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
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
7 changes: 2 additions & 5 deletions integration/test/ParseObjectTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,7 @@ describe('Parse Object', () => {
});

obj.increment('objectField.number', 15);
Copy link
Member

@dplewis dplewis Apr 15, 2021

Choose a reason for hiding this comment

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

The following test fails. Can you add it to the PR?

fit('can increment array nested fields', async () => {
    const obj = new TestObject();
    obj.set('items', [ { value: 'a', count: 5 }, { value: 'b', count: 1 } ]);
    await obj.save();

    obj.increment('items.0.count', 15);
    await obj.save();

    const query = new Parse.Query(TestObject);
    const result = await query.get(obj.id);
    assert.equal(result.get('items')[0].count, 20);
  });

Copy link
Member

@mtrezza mtrezza Apr 20, 2021

Choose a reason for hiding this comment

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

How would we differentiate between:

{
  "a": {
    "b": [
      { "c": 0 }
    ]
  }
}

and

{
  "a": {
    "b": {
      "0": {
        "c": 0
      }
    }
  }
}

Edit: I just looked up the MongoDB docs, and it seems MongoDB does not care, it apparently interprets "0" as index if it is an array and as key if it is an object. So that logic would have to be applied internally on the Parse Object as well.

assert.deepStrictEqual(obj.attributes.objectField, {
number: 20,
letter: 'a',
});
await obj.save();
assert.deepStrictEqual(obj.attributes.objectField, {
number: 20,
letter: 'a',
Expand Down Expand Up @@ -381,7 +378,7 @@ describe('Parse Object', () => {
} catch (error) {
assert.equal(
error.message,
'schema mismatch for TestObject.hello; expected String but got Object'
`Cannot create property 'dot' on string 'world'`
);
}
});
Expand Down
Loading