How can i order by attributes on a subdocument (lazy-loaded from belongsTo relation)?
I have:
Message::with(['conversation'])
->where(.....)
->get()
This returns:
[
{
"_id": "5aee075893782d1b1f460b13",
......
"updated_at": "2018-05-05 19:34:48",
"created_at": "2018-05-05 19:34:48",
"conversation": {
"_id": "5aee075793782d1b1f460b12",
"updated_at": "2018-05-06 12:21:23",
"created_at": "2018-05-05 19:34:47",
"messageCount": 5
}
}
]
I now need to order (the messages) by updated_at in conversation. I have tried ->orderBy('conversation.updated_at','desc'), but with no luck. I am guessing that the problem is that the conversation object is not available to orderBy due to lazy-loading...