Skip to content
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

Merged
merged 1 commit into from
Oct 25, 2023
Merged

Conversation

khaperets
Copy link
Contributor

Q A
Type improvement
BC Break yes
Fixed issues #1195

Summary

See #1195

@khaperets
Copy link
Contributor Author

#1624

@malarzm
Copy link
Member

malarzm commented Sep 6, 2023

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.

@khaperets
Copy link
Contributor Author

@malarzm Added optional parameter insertEmptyArray

@khaperets
Copy link
Contributor Author

@malarzm ping :)

@malarzm
Copy link
Member

malarzm commented Oct 1, 2023

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 2.6.x branch, some of the errors will go away. Other things (in random order)

  1. Same feature should be made available for EmbedMany association
  2. XML mapping support is missing, you can take a look here https://github.com/doctrine/mongodb-odm/blob/2.6.x/lib/Doctrine/ODM/MongoDB/Mapping/Driver/XmlDriver.php#L454 how bool-ish attributes should be handled. XSD (https://github.com/doctrine/mongodb-odm/blob/2.6.x/doctrine-mongo-mapping.xsd) file shall be updated accordingly
  3. New option should be added to https://github.com/doctrine/mongodb-odm/blob/2.6.x/lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadata.php#L155. Combined with 1 this should effectively make ?? false construct not needed in your code
  4. How about naming the feature storeEmptyArray? Right now we're strictly talking about inserting document, but there's more to consider like clearing a persistent collection, which right now issues a $unset query here https://github.com/doctrine/mongodb-odm/blob/2.6.x/lib/Doctrine/ODM/MongoDB/Persisters/CollectionPersister.php#L82
  5. The documentation should be updated

@khaperets
Copy link
Contributor Author

Thanks for your detailed answer. I'll get to it soon.
P.S. I hope you had a good rest :)

@khaperets
Copy link
Contributor Author

  1. Done
  2. Done
  3. Done
  4. Renamed the new functionality.
  5. Done

@khaperets
Copy link
Contributor Author

@malarzm ping :)

Copy link
Member

@malarzm malarzm left a 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:

  1. 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
  2. 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)

@malarzm malarzm added this to the 2.6.0 milestone Oct 23, 2023
@khaperets
Copy link
Contributor Author

  1. Done
  2. Done

Thank you very much for the code review!

Copy link
Member

@malarzm malarzm left a 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
Copy link
Member

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 👀

Copy link
Contributor Author

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

@khaperets
Copy link
Contributor Author

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?

Done

@malarzm malarzm merged commit 2d57e7e into doctrine:2.6.x Oct 25, 2023
12 checks passed
@malarzm
Copy link
Member

malarzm commented Oct 25, 2023

Awesome! Thank you @khaperets very much for sticking with us (and me not replying promptly) and seeing this to an end 🍻

@khaperets
Copy link
Contributor Author

@malarzm Many thanks for your help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants