2013-10-22 38 views
2

我有3個型號ReportServerPlatform。我需要執行一個涉及三連接所有3個模型並基於此進行查詢的查詢。但是,當我嘗試三重連接時,出現以下錯誤:Rails Triple加入

ActiveRecord :: ConfigurationError:未找到名爲「platform」的關聯;也許你拼錯了嗎?

這裏是我的模型

報告

class Report < ActiveRecord::Base 

belongs_to :server 

delegate :company_id, :to => :server 

    class << self 

     def method(url, base_url) 
      Report.joins(:server).joins(:platform).where(:platforms => {:company_id => 5}).all 
     end 
    end 

end 

服務器

class Server < ActiveRecord::Base 

has_many :reports 
belongs_to :platform 

end 

平臺

class Platform < ActiveRecord::Base 

attr_accessible :company_id 

has_many :servers 

end 

回答

4

試試這個:(注意platforms它是必要的,因爲表名是複數):

Report.joins(:server => :platform).where(:platforms => {:company_id => 5}).all 
+0

對不起,我有一些錯別字。你的回答是正確的。謝謝。 – user2158382

+0

我想知道如何在連接字段的where子句中指定不等式? – Chloe