class ReeDao::Agg
def call(dao, ids_or_scope, **opts, &block)
def call(dao, ids_or_scope, **opts, &block) scope = if ids_or_scope.is_a?(Array) && ids_or_scope.any? { _1.is_a?(Integer) } return [] if ids_or_scope.empty? dao.where(id: ids_or_scope) elsif ids_or_scope.is_a?(Integer) dao.where(id: ids_or_scope) else ids_or_scope end list = scope.is_a?(Sequel::Dataset) ? scope.all : scope if opts[:to_dto] list = list.map do |item| list = opts[:to_dto].call(item) end end load_associations(dao.unfiltered, list, **opts, &block) if block_given? if ids_or_scope.is_a?(Array) list.sort_by { ids_or_scope.index(_1.id) } else list end end