So I've got three tables I'm trying to join and two of them contain
the same column name. I need both columns in my final dataset. I'm
having a hard time trying to formulate everything so that these
aliases come through. Can anyone help? I'll reference the standard
Album/Artist paradigm and add 'Producer':

Album.join(:artists, :id => :artist_id).join(:producers, :id
=> :albums__producer_id)
=> SELECT * FROM `albums` INNER JOIN `artists` ON (`artists`.`id` =
`albums`.`artist_id`) INNER JOIN `producers` ON (`producers`.`id` =
`albums`.`producer_id`)

But, both the `artists` table and `producers` table contain a column
`name`. All I want to do is alias those as `artist_name` and
`producer_name` in my final query. I've tried adding a 'select' along
with the triple underscore alias, but then that removes the `select *`
for the albums themselves:

Album.join(:artists, :id
=> :artist_id).select(:artists__name___artist_name).join(:producers, :id
=> :albums__producer_id)
=> SELECT `artists.name` AS `artist_name` FROM `albums` INNER JOIN
`artists` ON (`artists`.`id` = `albums`.`artist_id`) INNER JOIN
`producers` ON (`producers`.`id` = `albums`.`producer_id`)

I've tried adding select_more, but since everything is already
selected it doesn't add anything! And I can't find a way to add a
select for `albums`.* back into the query... :albums__* isn't valid
and 'albums.*' literally inserts a quoted string into the SQL which is
invalid.

Any help would be greatly appreciated, I'm trying to avoid just
writing straight SQL as that doesn't feel right anymore...Ruby has
spoiled me. :)

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to