Support the ongoing development of Laravel.io →
posted 9 years ago
Eloquent
Last updated 2 years ago.
0

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.

0

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.

0

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();
Last updated 9 years ago.
0

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.

0

Glad I could help.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

jerauf jerauf Joined 16 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.