I have the following models in my application:
class Order < Sequel::Model
many_to_one(:client, class: 'Client', key: :client_id)
end
class Client < Sequel::Model
one_to_many(:images, class: 'Image', key: :client_id, eager: :file)
end
class Image < Sequel::Model
many_to_one(:file, class: 'File', key: :file_id, eager: :namespace)
end
class File < Sequel::Model
many_to_one(:namespace, class: 'Namespace', key: :namespace_id)
end
class Namespace < Sequel::Model
end
I can fetch all Orders
for all Clients
with account_id=1
using eager_graph (eager_graph because the search column is in the client
table):
orders = Order.eager_graph(:client).where(account_id: 1)
What is the best strategy to eager load all this entities?
If I change it to .eager_graph(client: :images)
the result will be a big query with a lot of joins.
Is it possible to have a separate query for every nested associations, like it was used only the .eager
method?
I trying to fine tune this because of performance issues.
Thanks in advance.