-
-
Notifications
You must be signed in to change notification settings - Fork 594
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
[bug] Fix increment bug for nested array object field #1343
[bug] Fix increment bug for nested array object field #1343
Conversation
Fixes parse-community/parse-server#6687 by modifying the estimateAttribute function logic in src/ObjectStateMutations.js.
Generated by 🚫 dangerJS |
f948e3c
to
4c374de
Compare
Codecov Report
@@ Coverage Diff @@
## master #1343 +/- ##
==========================================
- Coverage 99.94% 99.23% -0.71%
==========================================
Files 60 60
Lines 5847 5919 +72
Branches 1311 1347 +36
==========================================
+ Hits 5844 5874 +30
- Misses 3 44 +41
- Partials 0 1 +1
Continue to review full report at Codecov.
|
@@ -304,10 +304,7 @@ describe('Parse Object', () => { | |||
}); | |||
|
|||
obj.increment('objectField.number', 15); |
There was a problem hiding this comment.
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);
});
There was a problem hiding this comment.
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.
Does this PR also address calling other atomic ops on nested keys, such as Also, see my analysis point 3; is there a change in Parse Server necessary that accompanies this PR? Also, I think we need to add a test which increments a nested field for an existing object, that has not been fetched but created with |
Fixes parse-community/parse-server#6687
When I ran the below script,
I got this output:
The array was converted into a JSON object. I fixed this behaviour so that the resulting output is as expected:
I have modified the
estimateAttribute
function logic insrc/ObjectStateMutations.js
and modified relevant tests accordingly.