簡體   English   中英

如何在Rails中的eager_load中執行左外連接?

[英]How to do a left outer join in a eager_load in Rails?

以下查詢

Install.eager_load(customer: :invoices).includes(calendar_appointment: :technician).where("state = 'scheduled' AND start_time < ?", Date.tomorrow)

真的很慢,我希望只返回沒有關聯發票的安裝,因為這會使它運行得更快。 我該怎么做呢? 此外,任何有關提高此查詢速度的想法都會有所幫助,相應的表將被編入索引。

不知道協會是如何定義的,但這是我對它的抨擊:

Install
.joins("inner join invoices on installs.id = invoices.install_id")
.includes(calendar_appointment: :technician)
.where("state = 'scheduled' AND start_time < ? AND invoices.install_id IS NULL", Date.tomorrow)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM