-
Type:
Bug
-
Resolution: Fixed
-
Priority:
Major - P3
-
Affects Version/s: None
-
None
-
3
-
Needed
-
-
None
-
None
-
None
-
None
-
None
-
None
GitHub issues:
- https://github.com/mongodb/laravel-mongodb/issues/1430
- https://github.com/mongodb/laravel-mongodb/issues/1294
- https://github.com/mongodb/laravel-mongodb/issues/730
has(), whereHas(), doesntHave() and whereDoesntHave() have never worked on embedsOne and embedsMany relations. Every document model is routed to addHybridHas(), which queries the related collection; embedded documents have none, and assertHybridRelationSupported() now rejects them with a misleading "not supported for hybrid query constraints" error. #1430 was closed as won't fix in 2018, while the docs' Feature Compatibility page marks "Querying Relations" as supported.
Fix (branch embedded-where-has): match the embedded documents inside the parent document.
- EmbedsMany: $elemMatch with the compiled constraints, or field.0 $exists without constraints.
- EmbedsOne: the constraints prefixed with the field name, with $and/$or/$nor handled recursively, combined with $type: object. Other top-level operators such as $expr throw.
- Counts (has('addresses', '>=', 2)) on EmbedsMany without constraints use $expr with $size.
Remaining limitation: a count with constraints throws, as find syntax cannot drive the $filter expression it needs. It can be supported with a RelationLookup self-lookup once the Filament bridge (#3663) lands.
- depends on
-
PHPLARA-330 Embedded relation aggregates and eager loaded constraints return wrong results
-
- Ready for Work
-