Open stefanschindler opened 2 years ago
Instead of necroposting next time create a new issue.
@divine didn't I open a new issue? Maybe the problem is already known, but the other issue was closed in 2018 without any reason and it still doesn't seem to work.
+1
Same problem here, Message::with('user') works well, but User::with('messages') came a empty array, and I didn't find any solution in others posts
I have the same issue with laravel 8 and jenssegers/mongodb 3.8.x
it works only with belongsTo relation
hasone or has many return empty response cause the foreign key and primary id is objectID while package search in collection with string type
Description:
I have a hybrid setup with MySQL and MongoDB. Eager Loading latest item of relation is not working correctly. I want to load a list of customers with their latest metrics (by date) eager loaded. Instead of loading the latest metric for every customer, it just loads the latest metric in total.
Steps to reproduce
The Customer Class (Mysql):
The Metrics Class (Mongodb):
The code that loads the data:
I also tried to use
first()
instead oflimit(1)->get()
, but that led to the same result.Expected behaviour
It should return all customers with their latest metrics, similar to this:
Actual behaviour
Only the newest metric of all customers is returned, which results, that most customers have empty metrics:
@jenssegers seems to be the same problem as this issue: https://github.com/jenssegers/laravel-mongodb/issues/1042#issue-191570133