-
-
Notifications
You must be signed in to change notification settings - Fork 506
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
Views #2166
Conversation
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.
Looking good!
|
||
case $metadata->isEmbeddedDocument: | ||
throw MongoDBException::cannotCreateRepository($documentName); | ||
break; |
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.
Isn't this reported by PHPStan as unreachable code?
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.
Nope 🤔
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.
Could you remove it? :)
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.
Build is failing tho ;)
EDIT: seems like usual stuff, restarted failed builds for you
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: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:
AbstractRepositoryFactory
to throw exceptions when trying to get the repository for an invalid class (e.g. an embedded document)