我有(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