Sha256: 5c4acfc7248ca0ab831aac890da9419d14c52dcfa01a6bf1b3300d1f941d2cfa

Contents?: true

Size: 568 Bytes

Versions: 1

Compression:

Stored size: 568 Bytes

Contents

module Nazrin
  class DataAccessor
    class ActiveRecord < Nazrin::DataAccessor
      # load from activerecord
      def load_all(ids)
        records_table = {}
        options.each do |k, v|
          @model = model.send(k, v)
        end
        model.where(id: ids).each do |record|
          records_table[record.id] = record
        end
        ids.map do |id|
          records_table.select { |k, _| k == id.to_i }[id.to_i]
        end.reject(&:nil?)
      end

      def data_from_response(res)
        res.data.hits.hit.map(&:id)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nazrin-2.6.2 lib/nazrin/data_accessor/active_record.rb