def load_records(relation = nil, paging = true)
      begin
        # reset values.
        # @config[:records] is set to the return of this method, we we won't change that here.
        @config[:records_total] = 0
        @config[:records_filtered] = 0
        @config[:error] = nil

        Incline::Log::debug "Loading records for data tables request #{draw}."

        # Get the default starting scope if necessary.
        relation ||= @config[:starting_scope].call

        # store the unfiltered count.
        @config[:records_total] = relation.count

        # If we have search parameters and any of the search parameters is a regular expression or
        # one or more columns being searched is not a database column, then filtering must be done
        # locally.
        filter_local =
            !(search.blank? && columns.reject{|c| c[:search].blank? }.blank?) &&
                (
                    # main search is a regex.
                search.is_a?(::Regexp) ||
                    # one or more column searches is a regex.
                    columns.select{|c| c[:search].is_a?(::Regexp)}.any? ||
                    # one or more searchable columns is not in the database model
                    columns.reject {|c| !c[:searchable] || relation.model.column_names.include?(c[:name].to_s) }.any?
                )

        order_local = ordering.blank? || ordering.reject{|k,_| relation.model.column_names.include?(k.to_s)}.any?

        Incline::Log::debug "Filtering will be done #{(filter_local || order_local) ? 'application' : 'database'}-side."
        Incline::Log::debug "Ordering will be done #{order_local ? 'application' : 'database'}-side."

        unless filter_local
          ###  Database Side Individual Filtering  (AND) ###
          columns.reject{|c| c[:search].blank? || c[:name].blank?}.each do |col|
            relation = relation.where("(UPPER(\"#{col[:name]}\") LIKE ?)", "%#{col[:search].upcase}%")
          end

          ###  Database Side Multiple Filtering  (OR) ###
          unless search.blank?
            srch = "%#{search.upcase}%"
            cols = columns.select{|c| c[:searchable]}.map{|c| c[:name].to_s }.reject{|c| c.blank?}
            if cols.any?
              relation = relation.where(
                  cols.map{|c| "(UPPER(\"#{c}\") LIKE ?)"}.join(' OR '),
                  *(cols.map{ srch })
              )
            end
          end
        end

        ###  Database Side Ordering  ###
        unless order_local
          relation = relation.order(ordering)
        end

        # Now we have two paths, if we are filtering/ordering locally, we need to return everything up to this point and
        # perform our filters before limiting the results.
        # If we filtered and ordered at the database, then we can limit the results there as well.
        if filter_local || order_local
          # execute the query
          relation = relation.to_a

          ###  Application Side Ordering  ###
          if order_local
            ordering_list = ordering.to_a
            relation.sort!{|a,b| local_sort(a, b, ordering_list) }
          end

          ###  Local Individual Filtering   (AND) ###
          columns.reject{|c| c[:search].blank? || c[:name].blank?}.each do |col|
            name = col[:name].to_s
            srch = col[:search]
            relation =
                if srch.is_a?(::Regexp)
                  relation.select { |item| get_value(item, name) =~ srch }
                else
                  srch = srch.to_s.upcase
                  relation.select { |item| get_value(item, name).to_s.upcase.include?(srch) }
                end
          end

          ###  Local Multiple Filtering  ###
          unless search.blank?
            cols = columns.select{|c| c[:searchable]}.map{|c| c[:name].to_s }.reject{|c| c.blank?}
            relation =
                if search.is_a?(::Regexp)
                  relation.select{|item| cols.find{|col| get_value(item,col) =~ search} }
                else
                  srch = search.to_s.upcase
                  relation.select{|item| cols.find{|col| get_value(item,col).to_s.upcase.include?(srch) }}
                end
          end

          # store the filtered count.
          @config[:records_filtered] = relation.count

          if paging
            # apply limits and return.
            relation                   = relation[start..-1]
            if length > 0
              relation = relation[0...length]
            end
          end
          relation
        else
          # store the filtered count.
          @config[:records_filtered] = relation.count

          if paging
            # apply limits and return.
            relation                   = relation.offset(start)
            if length > 0
              relation = relation.limit(length)
            end
          end
          relation.to_a
        end
      rescue =>err
        @config[:error] = err.message
        Incline::Log::error err
        [ ]
      end
    end
def load_records(relation = nil, paging = true)
      begin
        # reset values.
        # @config[:records] is set to the return of this method, we we won't change that here.
        @config[:records_total] = 0
        @config[:records_filtered] = 0
        @config[:error] = nil

        Incline::Log::debug "Loading records for data tables request #{draw}."

        # Get the default starting scope if necessary.
        relation ||= @config[:starting_scope].call

        # store the unfiltered count.
        @config[:records_total] = relation.count

        # If we have search parameters and any of the search parameters is a regular expression or
        # one or more columns being searched is not a database column, then filtering must be done
        # locally.
        filter_local =
            !(search.blank? && columns.reject{|c| c[:search].blank? }.blank?) &&
                (
                    # main search is a regex.
                search.is_a?(::Regexp) ||
                    # one or more column searches is a regex.
                    columns.select{|c| c[:search].is_a?(::Regexp)}.any? ||
                    # one or more searchable columns is not in the database model
                    columns.reject {|c| !c[:searchable] || relation.model.column_names.include?(c[:name].to_s) }.any?
                )

        order_local = ordering.blank? || ordering.reject{|k,_| relation.model.column_names.include?(k.to_s)}.any?

        Incline::Log::debug "Filtering will be done #{(filter_local || order_local) ? 'application' : 'database'}-side."
        Incline::Log::debug "Ordering will be done #{order_local ? 'application' : 'database'}-side."

        unless filter_local
          ###  Database Side Individual Filtering  (AND) ###
          columns.reject{|c| c[:search].blank? || c[:name].blank?}.each do |col|
            relation = relation.where("(UPPER(\"#{col[:name]}\") LIKE ?)", "%#{col[:search].upcase}%")
          end

          ###  Database Side Multiple Filtering  (OR) ###
          unless search.blank?
            srch = "%#{search.upcase}%"
            cols = columns.select{|c| c[:searchable]}.map{|c| c[:name].to_s }.reject{|c| c.blank?}
            if cols.any?
              relation = relation.where(
                  cols.map{|c| "(UPPER(\"#{c}\") LIKE ?)"}.join(' OR '),
                  *(cols.map{ srch })
              )
            end
          end
        end

        ###  Database Side Ordering  ###
        unless order_local
          relation = relation.order(ordering)
        end

        # Now we have two paths, if we are filtering/ordering locally, we need to return everything up to this point and
        # perform our filters before limiting the results.
        # If we filtered and ordered at the database, then we can limit the results there as well.
        if filter_local || order_local
          # execute the query
          relation = relation.to_a

          ###  Application Side Ordering  ###
          if order_local
            ordering_list = ordering.to_a
            relation.sort!{|a,b| local_sort(a, b, ordering_list) }
          end

          ###  Local Individual Filtering   (AND) ###
          columns.reject{|c| c[:search].blank? || c[:name].blank?}.each do |col|
            name = col[:name].to_s
            srch = col[:search]
            relation =
                if srch.is_a?(::Regexp)
                  relation.select { |item| get_value(item, name) =~ srch }
                else
                  srch = srch.to_s.upcase
                  relation.select { |item| get_value(item, name).to_s.upcase.include?(srch) }
                end
          end

          ###  Local Multiple Filtering  ###
          unless search.blank?
            cols = columns.select{|c| c[:searchable]}.map{|c| c[:name].to_s }.reject{|c| c.blank?}
            relation =
                if search.is_a?(::Regexp)
                  relation.select{|item| cols.find{|col| get_value(item,col) =~ search} }
                else
                  srch = search.to_s.upcase
                  relation.select{|item| cols.find{|col| get_value(item,col).to_s.upcase.include?(srch) }}
                end
          end

          # store the filtered count.
          @config[:records_filtered] = relation.count

          if paging
            # apply limits and return.
            relation                   = relation[start..-1]
            if length > 0
              relation = relation[0...length]
            end
          end
          relation
        else
          # store the filtered count.
          @config[:records_filtered] = relation.count

          if paging
            # apply limits and return.
            relation                   = relation.offset(start)
            if length > 0
              relation = relation.limit(length)
            end
          end
          relation.to_a
        end
      rescue =>err
        @config[:error] = err.message
        Incline::Log::error err
        [ ]
      end
    end
Applies the request against an ActiveRecord::Relation object.

 Returns the results of executing the necessary queries and filters as an array of models.