[ rails ] arel_table alias

“alias” means “as” SQL

h = Hoge.arel_table.alias('h')
Fuga.joins(h).select(h[:bar])

 

SELECT
h.`bar`
FROM
fugas
INNER JOIN
hoges AS 'h' ON h.`id` = `fugas`.`hoge_id`

“project” means “projection┬ácolumn”

 

ref : http://qiita.com/yamagen0915/items/b1721a9d1ea076f8cdc5

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s