I have 2 models. Report and Server that have a belongs_to and has_many relationship. I created an accessor method using delegate that
Report
Server
delegate
This should do the trick
Report.joins(:server).where('servers.company_id = ?', 5)
you could also add a scope for this like so
scope :with_company_id, lambda {|id| joins(:server).where('servers.company_id = ?', id) }
and then write
Report.with_company_id(5)