Mostly because the query you are building is being split into many queries. You may try orderBy('credit_name.sort_no')
, but I don't think it will work. You most likely need to build query some different way or sort this data manually.
That doesn't work. Any suggestions about building the query in a different way? credit_name is a hasMany relationship to CreditRole. So, these results need to be sorted by sort_no. And CreditRole's results need to be sorted by their own sort_no column too.
I'm not sure why you have the following in your query if you're doing a sub-query from credit_name:
->with('credit_name.has_name')
->with('credit_name.has_biography')
Also, is ->with('credit_role') not the same table you're already selecting from (CreditRole::)?
I'm not sure if the following will work but give it a try:
$original_authors = CreditRole::with(array('credit_name' => function($query)
{
$query->where('run_type', '=', 'OR')
->orderby('credit_name.sort_no', 'asc');
},
'has_replacements' => function($query)
{
$query->where('run_type', '=', 'RE');
}))
->where('credit_level', '=', 'S')
->where('author_status', '=', 'O')
->where('show_id', '=', $id)
->orderBy('credit_role.sort_no')
->get();
Ah, ok. I see what I was doing wrong.
has_name, has_biography and has_role are hasOne relationships. The perpetrators were has_name and has_biography. It sorts properly if I put them in the credit_name array.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community