3

ReportServer、および の3 つのモデルがありPlatformます。3 つのモデルすべてをトリプル結合し、それに基づいてクエリを作成するクエリを実行する必要があります。しかし、トリプル結合しようとすると、次のエラーが発生します

ActiveRecord::ConfigurationError: 「プラットフォーム」という名前の関連付けが見つかりませんでした。おそらくあなたはそれを書き間違えましたか?

ここに私のモデルがあります

報告

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

1 に答える 1

5

sこれを試してください: (テーブル名が複数形であるため、 inplatformが必要であることに注意してください):

Report.joins(:server => :platform).where(:platforms => {:company_id => 5}).all
于 2013-10-22T20:08:37.710 に答える