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

Throw exception on duplicate database names within a document #1903

Merged

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Nov 26, 2018

Q A
Type bug
BC Break yes
Fixed issues Fixes #924

Summary

As described in #924, this adds check to the metadata drivers to ensure that database names are not reused within a document. This check is done in the metadata drivers to ensure that it's still possible to re-declare a field from a parent class to change its mapping.

@alcaeus alcaeus force-pushed the fail-duplicate-field-names-mapping-drivers branch from 2f54468 to ebc7dda Compare November 26, 2018 20:34
@alcaeus
Copy link
Member Author

alcaeus commented Nov 26, 2018

I was able to move the check to the metadata class, so we don't need to implement it in every driver 🎉

With this change, we're now throwing an exception if there are two properties with different names mapped to the same field in the database and both are not marked as notSaved. If they share the same property name we assume the original mapping is overwritten, while if either of them is marked as notSaved we also don't throw a mapping error since we won't have any conflicts due to the mapping. The sorted group relationships in the user document in our tests shows where this can be useful.

To allow a mapping references and embedded relationships as notSaved, I had to drop the NotSaved annotation and move it to the AbstractField annotation to allow references and embedded documents being marked as readonly. I'll need to come up with some more tests to ensure this works consistently, so I might extract that change to a separate pull request.

Copy link
Member

@jmikola jmikola left a comment

Choose a reason for hiding this comment

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

Logic in mapField() looks sound. Left a few other comments.

@alcaeus alcaeus force-pushed the fail-duplicate-field-names-mapping-drivers branch from ebc7dda to 68853f9 Compare November 28, 2018 06:38
@alcaeus alcaeus merged commit cc367cf into doctrine:master Nov 29, 2018
@alcaeus alcaeus deleted the fail-duplicate-field-names-mapping-drivers branch November 29, 2018 06:21
alcaeus added a commit to alcaeus/mongodb-odm that referenced this pull request Jan 11, 2019
alcaeus added a commit to alcaeus/mongodb-odm that referenced this pull request Jan 11, 2019
alcaeus added a commit to alcaeus/mongodb-odm that referenced this pull request Jan 11, 2019
alcaeus added a commit to alcaeus/mongodb-odm that referenced this pull request Jan 11, 2019
alcaeus added a commit to alcaeus/mongodb-odm that referenced this pull request Jan 14, 2019
alcaeus added a commit to alcaeus/mongodb-odm that referenced this pull request Jan 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants