laravel-mongodb
laravel-mongodb copied to clipboard
PHPORM-238 Add support for `withCount` and other aggregations
Fix PHPORM-238
Implement this feature from Laravel: https://laravel.com/docs/11.x/eloquent-relationships#counting-related-models Counting relations with SQL is done using a subquery. For MongoDB, there is 2 ways:
- Making a query during eager loading, that count the objects for each result ID. This is an aggregation with a
$groupby foreign key. - Using
$lookupto load references and count them. The process would be similar for embedded relations (without the$lookup). But this doesn't work with hybrid relations.
Checklist
- [x] Add tests and ensure they pass
- [x] Support mongodb relationships
- [x] CANCELLED: Support hybrid relationships (PR reverted from Laravel: https://github.com/laravel/framework/pull/53679)
- [x] Support embedded relationships, contraint query not supported PHPORM-292