Reputation: 4520
I have 3 models Report
, Server
, and Platform
. I need to execute a query that involves triple joining all 3 models and making the query based on that. But I get the following error whenever I try to triple join
ActiveRecord::ConfigurationError: Association named 'platform' was not found; perhaps you misspelled it?
Here are my models
Report
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
Server
class Server < ActiveRecord::Base
has_many :reports
belongs_to :platform
end
Platform
class Platform < ActiveRecord::Base
attr_accessible :company_id
has_many :servers
end
Upvotes: 3
Views: 1385
Reputation: 8003
Try this: (note the s
in platform
it is needed because the table names are plural):
Report.joins(:server => :platform).where(:platforms => {:company_id => 5}).all
Upvotes: 5