def set_includes_for_columns(action = :list, sorting = active_scaffold_config.list.user.sorting)
      @cache_associations = true
      columns =
        if respond_to?(:"#{action}_columns", true)
          send(:"#{action}_columns")
        else
          active_scaffold_config.send(action).columns.visible_columns(flatten: true)
        end
      joins_cols, preload_cols = columns.select { |c| c.includes.present? }.partition do |col|
        includes_need_join?(col, sorting) && !grouped_search?
      end
      active_scaffold_references.concat joins_cols.map(&:includes).flatten.uniq
      active_scaffold_preload.concat preload_cols.map(&:includes).flatten.uniq
      set_includes_for_sorting(columns, sorting) if sorting.sorts_by_sql?
    end
def set_includes_for_columns(action = :list, sorting = active_scaffold_config.list.user.sorting)
      @cache_associations = true
      columns =
        if respond_to?(:"#{action}_columns", true)
          send(:"#{action}_columns")
        else
          active_scaffold_config.send(action).columns.visible_columns(flatten: true)
        end
      joins_cols, preload_cols = columns.select { |c| c.includes.present? }.partition do |col|
        includes_need_join?(col, sorting) && !grouped_search?
      end
      active_scaffold_references.concat joins_cols.map(&:includes).flatten.uniq
      active_scaffold_preload.concat preload_cols.map(&:includes).flatten.uniq
      set_includes_for_sorting(columns, sorting) if sorting.sorts_by_sql?
    end
The actual algorithm to prepare for the list view