如何在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
我的意思是:在这里我可以设置别名tup表TwitterUserProfile在这段代码?
对于哪个参数:from=>
使用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