如何在 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=>?
最佳答案
在您想要关联该表的模型中使用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
关于mysql - 如何在 Ruby On Rails 3 中为 MySQL 表设置别名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5716367/