This repository was archived by the owner on Sep 6, 2022. It is now read-only.
Support for mapping\filtering entities in ndb connection field #25
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR contains support for post NDB query interference to achieve mapping and filtering of entities fetched by NDB queries resolved within NDBConnectionFields.
It's very useful in situations where there's a many to many relation between two NDB models and you need to paginate over them.
See the added tests for an example.
Example explained -
A new
Reader
model was added. Each reader may have read multiple articles, and each article may have been read by multiple readers. The many to many relation is implemented using theArticleReader
model which represents that some reader has read an article and contains the reader key and article key.Now, in order to paginate over all the article readers, the
readers
property was added toArticleType
:readers = NdbConnectionField(ReaderType, entities_mapper=readers_mapper, entity_filter=reader_filter)
Notice that
ArticleType
'sresolve_readers
returns a query for all theArticleReader
entities.Upon resolving it
readers_mapper
is called and maps each article reader to the appropriate reader.Later we filter the readers in
reader_filter
and only return the readers that are alive.