我有(Rails中3.2.13):如何使用连接到两个表
class User < ActiveRecord::Base
has_many :app_event_login_logouts
end
class AppEventLoginLogout < ActiveRecord::Base
belongs_to :user
end
,并想拿回类似:
AppEventLoginLogoug.select("id, type, users.email").joins(:user)
基本上是id,键入来自app_event_login_logouts和用户的电子邮件,但这似乎不起作用。什么是正确的语法?
THX,为什么不反向的工作?像AppEventLoginLogout.joins(:用户)? – timpone
没有区别。你尝试过吗?在我机器的工作。试试这个如果不是'AppEventLoginLogout.joins(:user).select('app_event_login_logouts.id,app_event_login_logouts.type,users.email')' –
thx,那有效。我以为我试过了这个组合。需要一些咖啡;-) – timpone