I'm having difficulty to let the laravel query order by a date field of a nested query. This is what I came up with
$twitterStatuses = ProjectTwitterStatus::with(array('twitterStatus' => function($query) {
$query->select('id','datetime','text','twitter_user_id','raw_created_at','datetime')
->with(array('twitterUser' => function($query) {
$query->select('id','id_str','screen_name','profile_image_url','screen_name','name','description');
}))
->with(array('twitterStatusTag' => function($query) {
$query->with('tag');
}))
->with(array('twitterUserTag' => function($query) {
$query->with('tag');
}));
}))
->orderBy('datetime')
->paginate(15);
ProjectTwitterStatus holds only a projectId and the twitterStatusId, the last one identifies the tweet in twitterStatus. The result needs to be ordered by the datetime of the tweet, and that is availible in the twitterStatus model. The above depicts what I thought it shoud be, but that did not work, any thoughts?
You should be using orderBy on the nested relation which you want to inherit order precedence from not on the root.
I tried that, but that results in an extreamly wierd ordering, the ordering restarts more than once.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community