我試圖建立一個連接如下:的Rails:加入多個表給表「table1.table2」不存在
UserLog.find(:all, :joins => " JOIN client_inspector ON user_log.COMPUTER_NAME = client_inspector.Retrieving_Hostname ", :select=> "DISTINCT user_log.COMPUTER_NAME, client_inspector.Retrieving_Hostname ")
但它給我下面的錯誤 - >
ActiveRecord::StatementInvalid (Mysql2::Error: Table 'user_log.client_inspector' doesn't exist: SELECT DISTINCT user_log.COMPUTER_NAME, client_inspector.Retrieving_Hostname FROM `user_log` JOIN client_inspector ON user_
log.COMPUTER_NAME = client_inspector.Retrieving_Hostname):
我理解的MySQL錯誤,但爲什麼Rails的這樣做呢?
我沒有任何創建的模型將這兩個表關聯在一起。我想要做的是能夠通過不同於Ruby默認設置的列來加入。
有沒有其他方法可以做到這一點?
編輯:我更新包括我的實際表名稱。
是的,這是等價的,但我不明白爲什麼它這樣做。我更新了包含我的實際表名。 – hacket
事實證明,我需要將表格名稱限定爲數據庫{dot} table ... whodda thunk。 – hacket