如何在Ruby On Rails 3中为MySQL表设置别名?
data = TUP.all :select =>
"DATE(tup.created_at) as date
, ROUND(SUM(fo_count)/#{authors_count}) AS followers"
,:joins => "INNER JOIN tlsts AS tl ON tl.user_id = tup.user_id"
,:conditions => condition
我的意思如下:我可以在此代码中为表TwitterUserProfile设置别名 tup 吗?
对于什么参数:from => ?
答案 0 :(得分:1)
在您希望加入该表的模型中使用set_table_name :table_name
。例如:
class UserRole < ActiveRecord::Base
set_table_name :user_roles # Add user_roles table to UserRole model so, you can make query to that table like: @user_roles = UserRole.all/ @user_role = UserRole.find(params[:id]) etc.
end