class ReeDaoAggTest::AggUsers

def call(ids_or_scope, **opts)

def call(ids_or_scope, **opts)
  agg(users, ids_or_scope, **opts) do |users_list|
    belongs_to :organization
    has_many :books do |books_list|
      has_one :author
      has_many :chapters
      has_many :reviews, -> { reviews_opts } do |reviews_list|
        has_one :review_author
        field :review_calculatetable_field, -> { some_method(reviews_list) }
      end
      field :book_calculatetable_field, -> { change_book_titles(books_list) }
    end
    has_one :passport, -> { passport_opts }
    has_one :custom_field, -> { custom_field_opts }
    field :user_calculatetable_field, -> { some_method(users_list) }
  end
end

def change_book_titles(books_list)

def change_book_titles(books_list)
  books_list.each do |book|
    book.title = "#{book.title.upcase} changed"
  end
end

def custom_field_opts

def custom_field_opts
  {
    scope: books.where(title: "1984")
  }
end

def passport_opts

def passport_opts
  {
    foreign_key: :user_id,
    scope: user_passports
  }
end

def reviews_opts

def reviews_opts
  { autoload_children: true }
end

def some_method(list)

def some_method(list)
  list.each { _1.some_field = :some_value if _1.respond_to?(:some_field=) }
end