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

Views #2166

Merged
merged 12 commits into from Apr 1, 2020
Merged

Views #2166

merged 12 commits into from Apr 1, 2020

Conversation

alcaeus
Copy link
Member

@alcaeus alcaeus commented Feb 18, 2020

Q A
Type feature
BC Break no
Fixed issues Fixes #1925.

Summary

As per the ticket, this is an implementation of MongoDB views in ODM. Views are treated as a separate mapped object class, similar to files, documents, and query results. Views cannot be proxied (for now), and their repository must implement a specific ViewRepository interface. Thus, a view cannot be mapped without a custom repository.

The ViewRepository interface defines a single method:

public function createViewAggregation(Builder $builder) : void;

This method receives an aggregation builder instance based on the document specified in the viewOn mapping attribute. This was done as the view needs to be static, so any dynamic changes (e.g. by choosing a different class to base the view on) must be avoided. The aggregation builder instance is then used to build the aggregation pipeline that defines the view. Exposing a builder instance will allow for more flexibility down the line, as we could leverage this builder to optimise queries, e.g. if there is an inverse reference pointing to a view).

As for always requiring a custom repository, I had considered letting the mapped class define the pipeline, but I thought that the repository was a better fit than a static method on the entity (potentially with a custom name).

This PR covers:

  • Annotation and XML mappings for views
  • Schema manager logic to create and drop views
  • Refactoring AbstractRepositoryFactory to throw exceptions when trying to get the repository for an invalid class (e.g. an embedded document)
  • Refactoring the mapping driver test to use the document manager created: this allows us to better test mappings
  • Documentation
  • Allow using views as targetDocument for references, including proxy handling

@alcaeus alcaeus added Feature Release Blocker Release Blockers must be resolved before the milestone can be closed. labels Feb 18, 2020
@alcaeus alcaeus added this to the 2.1.0 milestone Feb 18, 2020
@alcaeus alcaeus self-assigned this Feb 18, 2020
@alcaeus alcaeus added this to In progress in ODM 2.1 via automation Feb 18, 2020
@alcaeus alcaeus added this to 2.1 in Roadmap Feb 18, 2020
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.

Looking good!


case $metadata->isEmbeddedDocument:
throw MongoDBException::cannotCreateRepository($documentName);
break;
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this reported by PHPStan as unreachable code?

Copy link
Member Author

Choose a reason for hiding this comment

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

Nope 🤔

Copy link
Member

Choose a reason for hiding this comment

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

Could you remove it? :)

docs/en/reference/annotations-reference.rst Outdated Show resolved Hide resolved
docs/en/reference/annotations-reference.rst Outdated Show resolved Hide resolved
lib/Doctrine/ODM/MongoDB/Mapping/ClassMetadataFactory.php Outdated Show resolved Hide resolved
lib/Doctrine/ODM/MongoDB/Mapping/MappingException.php Outdated Show resolved Hide resolved
lib/Doctrine/ODM/MongoDB/Utility/LifecycleEventManager.php Outdated Show resolved Hide resolved
tests/Doctrine/ODM/MongoDB/Tests/SchemaManagerTest.php Outdated Show resolved Hide resolved
ODM 2.1 automation moved this from In progress to Reviewer approved Mar 27, 2020
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.

Build is failing tho ;)

EDIT: seems like usual stuff, restarted failed builds for you

@alcaeus alcaeus merged commit 9f19a49 into doctrine:master Apr 1, 2020
ODM 2.1 automation moved this from Reviewer approved to Done Apr 1, 2020
@alcaeus alcaeus deleted the views branch April 1, 2020 15:52
@alcaeus alcaeus removed the Release Blocker Release Blockers must be resolved before the milestone can be closed. label Apr 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
No open projects
ODM 2.1
  
Done
Roadmap
2.1 (unsupported)
Development

Successfully merging this pull request may close these issues.

Support for MongoDB Views
4 participants