You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I query data from multiple tables in Query Builder, any tables with duplicate field names only appear once. Am I missing something? I know I can use aliases in select() to give them unique field names, but is that really necessary?
For example, I have two tables venues and concerts.
venues
name
short_name
id
created_at
updated_at
concerts
name
date
comment
venue_id
id
created_at
updated_at
If I run this query: $list = DB::table('venues')->leftJoin('concerts', 'venues.id', '=', 'concerts.venue_id')->get();
The result will only contain the following columns:
name [from concerts]
short_name
id [from concerts]
created_at [from concerts]
updated_at [from concerts]
date
venue_id
comment
It's a foregone conclusion that most tables will have created_at, updated_at and id fields. So when using joins I figured Laravel would have planned for duplicate field names between tables.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
When I query data from multiple tables in Query Builder, any tables with duplicate field names only appear once. Am I missing something? I know I can use aliases in select() to give them unique field names, but is that really necessary?
For example, I have two tables
venues
andconcerts
.If I run this query:
$list = DB::table('venues')->leftJoin('concerts', 'venues.id', '=', 'concerts.venue_id')->get();
The result will only contain the following columns:
It's a foregone conclusion that most tables will have
created_at
,updated_at
andid
fields. So when using joins I figured Laravel would have planned for duplicate field names between tables.Beta Was this translation helpful? Give feedback.
All reactions