dynamoid icon indicating copy to clipboard operation
dynamoid copied to clipboard

preload associations

Open mrkamel opened this issue 2 years ago • 1 comments

Hi!

Tt seems it's not possible to preload associations (didn't find it in the docs, code and github issues), but it would be highly valuable for e.g. belongs_to associations. Example:

class Company
  include Dynamoid::Document
end

class Product
  include Dynamoid::Document

  belongs_to :company
end

When i do:

Product.all.map(&:company).map(&:uuid).to_a it requests each company individually (typical N+1 issue). It would be nice to be able to Product.preload(:company).map(&:uuid).to_a such that the companies are loaded with a single query like usually the case when using ActiveRecord. Maybe i miss something.

Thanks in advance.

mrkamel avatar Apr 28 '22 08:04 mrkamel

Hi, indeed preloading isn't implemented. But it sounds like a cool (but toilful) feature. Will add it to the TODO list.

andrykonchin avatar Apr 29 '22 10:04 andrykonchin