Sha256: 9d345e6d5aaa2eaccdcd0a76b2c4868e7af3df1ddca41fab1ef88359907b2ccd

Contents?: true

Size: 567 Bytes

Versions: 3

Compression:

Stored size: 567 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

3 entries across 3 versions & 1 rubygems

Version Path
nazrin-2.6.1 lib/nazrin/data_accessor/active_record.rb
nazrin-2.6.0 lib/nazrin/data_accessor/active_record.rb
nazrin-2.5.0 lib/nazrin/data_accessor/active_record.rb