2
我有一個ActiveJob,其中一些參數已經用GlobalID進行了序列化。在ActiveJob中急切加載
執行工作時,我該如何加載一些相關模型?
class Foo
has_one :bar
end
class Bar
belongs_to :foo
field :some_field
end
class MyJob < ApplicationJob
queue_as :default
def perform(foo)
# How can I eager load bar ?
foo.bar.some_field # Hits the DB again without eager loading
end
end
這只是一個簡單的例子,但在我的應用我需要eager_load幾種模式,並smetimes我甚至有N + 1度的問題,而它(在不同的例子,沒有預先加載)
因此,如果我們需要Eager Loading,基本上[globalID](http://edgeguides.rubyonrails.org/active_job_basics.html#globalid)技巧就變得毫無用處了。 –