如何解决如何在Ruby On Rails 3中为表MySQL表设置别名?
| 如何在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
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。