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

Try to change the select of that query and use the id you need in that select and not the id of the joined table.

0

I don't follow.

Right now I've got:

    $shows = Show::join('shows_titles', 'shows_titles.id', '=', 'shows.titlenu')
					->with(array('productions' => function($query)
						{
						  $query->with('production_location')
						  			->orderBy('prodsort', 'asc');
						}))
					->where('title_container', 'LIKE', '%'.$search_final.'%')
					->orderBy('sorttitle', 'asc')
					->get();

The join is causing id to become ambiguous and, since the productions relationship uses the id in Show, it's not eager loading the results for productions.

However, I need to use the join because I need to sort by sorttitle which is in shows_titles.

Any suggestions would be greatly appreciated.

0

Does the show table also have and id field?

If so, rewrite your get() to the following:

get(array('show.*','shows_titles.field'))

This prevents you from getting twice the id field.

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.