Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sequel joining tables but I have overlapping column names. How do I alias these column names?

Tags:

ruby

sequel

Here is my code for joining two tables:

DB.from(:sources).join(:payloads, :source_id => :id)

The table names are :sources, :payloads.

The problem is that there is an :id column in payloads which overwrites the :id column in :sources. I need to use an alias so that I just obtain a mega table with all of the column names. However, as currently written and as my tables are currently structured, the :id columns are getting combined and the second table takes precedence. Does this make sense?

How do I make an alias so that the :id column from :sources still shows up?

like image 391
Jwan622 Avatar asked Jan 03 '15 18:01

Jwan622


1 Answers

To alias sources.id to a different name, use the Identifier aliases.

.select_append(:sources__id___source_id).join...
# *, `sources`.`id` AS 'source_id'
like image 167
Jiří Pospíšil Avatar answered Oct 17 '22 01:10

Jiří Pospíšil