-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Add support for flexible document references #3602
Comments
mp911de
added a commit
that referenced
this issue
May 21, 2021
Rename ReferenceReader to ReferenceLookupDelegate. Rename LazyLoadingProxyGenerator to LazyLoadingProxyFactory. Rename DefaultReferenceLoader to MongoDatabaseFactoryReferenceLoader. Reduce scope of LookupFunction and move it to ReferenceLookupDelegate. Extract some checks into methods to reflect the underlying concepts. Simplify code, convert variables to constants where possible. Original pull request: #3647. Closes #3602.
mp911de
changed the title
Add support for manual references.
Add support for flexible document references
May 21, 2021
# for free
to join this conversation on GitHub.
Already have an account?
# to comment
The goal is support linking documents without the need of using the fixed structure of a
DBRef
(related to: #2780).Linking via Entity id
The
@Id
value of the referenced entity is used for linking.The domain type serves as collection source on read.
Linking via custom object
The reference value used for storing is provided via a
DomainType -> ObjectReference
converter.The
lookup
attribute uses SpEL to create the filter query following the annotated query syntax from@Query
. The targetcollection
that can be either read from the source document, domain type or is a fixed value.The
lookup
filter can contain any valid expression as long as it is resolvable against the stored reference.Linking multiple entities
Linking a collection of entities follows the same conversion patterns as described above. The main difference is that the values are stored within an array.
The provided filter expression is created for every entry and concatenated via the
$or
operator.Element order can be messed up when loading documents from the store this way. The original order must be restored by using the filter as a reference without having to fetch objects one by one.
Lazy Loading
References can be resolved lazily delaying resolution on first access.
In this case on read a proxy is generated holding the actual source value and the lookup filter.
Object methods like (
toString
) on unresolved proxies shall not trigger resolution but be served from the available source value. On write, in case the Proxy never got resolved, the original source is written back to the collection without an attempt of resolving it.The text was updated successfully, but these errors were encountered: