gpt4 book ai didi

mysql - 如何在 Ruby On Rails 3 中为 MySQL 表设置别名?

转载 作者:行者123 更新时间:2023-11-29 14:51:09 25 4
gpt4 key购买 nike

如何在 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com