-
-
Notifications
You must be signed in to change notification settings - Fork 504
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
ReferenceMany: insert an empty array #2547
Conversation
Glad you decided to be "someone to pick that PR up"! 🎉 Unfortunately we still need to consider #1624 (comment), even more than before, after 6 more years of previous behaviour and no 3.0 on horizon. |
@malarzm Added optional parameter insertEmptyArray |
@malarzm ping :) |
Thanks for the patience while I've been on vacations :) This is a good start, however there are few things I need you to do.. First things first, please rebase your work atop current
|
Thanks for your detailed answer. I'll get to it soon. |
|
@malarzm ping :) |
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.
Thank you very much for changes, they're looking A-OK! We're almost there, one last thing we need to do is increase test coverage to reflect your latest changes as right now we might accidentally break stuff from CollectionPersister and don't know about it 🙈 These tests should be included:
- At least one property that AbstractDriverTestCase is asserting on should have
storeEmptyArray
set to true - this way we'll know the support in attributes and XML is on par - Take a look at https://github.com/doctrine/mongodb-odm/blob/2.6.x/tests/Doctrine/ODM/MongoDB/Tests/Functional/CollectionPersisterTest.php and add a test or two there - we want to make sure that after the collection is emptied, an empty array is in fact stored. No need to test nested paths and whatnot as that's already covered
We'll make sure to include this in 2.6.0 (cc @alcaeus)
Thank you very much for the code review! |
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.
One last thing I've caught, sorry it's that late in the process. Also if you'd been fixing that, mind squashing commits so there's just 1?
@@ -90,7 +90,8 @@ public function prepareInsertData($document) | |||
// of duplicated entries stored in the collection | |||
} elseif ( | |||
$mapping['type'] === ClassMetadata::MANY && ! $mapping['isInverseSide'] | |||
&& $mapping['strategy'] !== ClassMetadata::STORAGE_STRATEGY_ADD_TO_SET && ! $new->isEmpty() | |||
&& (! $new->isEmpty() || $mapping['storeEmptyArray']) | |||
&& $mapping['strategy'] !== ClassMetadata::STORAGE_STRATEGY_ADD_TO_SET |
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.
Caught this with a last glance, don't we have a bug here? An empty collection using addToSet
strategy will not have an empty array stored. A test may prove me wrong 👀
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.
Fixed, added a case to test
dce31ed
to
bc21d8e
Compare
Done |
Awesome! Thank you @khaperets very much for sticking with us (and me not replying promptly) and seeing this to an end 🍻 |
@malarzm Many thanks for your help! |
Summary
See #1195