Rails: ActiveRecord query based on association value

前端 未结 4 391
耶瑟儿~
耶瑟儿~ 2020-11-30 00:08

I have 2 models. Report and Server that have a belongs_to and has_many relationship. I created an accessor method using delegate that

4条回答
  •  情书的邮戳
    2020-11-30 01:06

    You can perform a query like this:

    Report.joins(:servers).where(:servers => {:company_id => 5})
    

    To me, this is the cleaner solution to raw SQL.

提交回复
热议问题