class method self.locate_many

Ruby on Rails 1.0.1

Last seen in v1.3.0

Available in: v1.0.1 v1.1.0 v1.2.1 v1.3.0

Signature

self.locate_many(gids, options = {})

Takes an array of GlobalIDs or strings that can be turned into a GlobalIDs. All GlobalIDs must belong to the same app, as they will be located using the same locator using its locate_many method.

By default the GlobalIDs will be located using Model.find(array_of_ids), so the models must respond to that finder signature.

This approach will efficiently call only one #find (or #where(id: id), when using ignore_missing) per model class, but still interpolate the results to match the order in which the gids were passed.

Options:

  • :only - A class, module or Array of classes and/or modules that are allowed to be located. Passing one or more classes limits instances of returned classes to those classes or their subclasses. Passing one or more modules in limits instances of returned classes to those including that module. If no classes or modules match, nil is returned.

  • :ignore_missing - By default, locate_many will call #find on the model to locate the ids extracted from the GIDs. In Active Record (and other data stores following the same pattern), #find will raise an exception if a named ID can’t be found. When you set this option to true, we will use #where(id: ids) instead, which does not raise on missing records.

Parameters

gids req
options opt = {}
Source
# File lib/global_id/locator.rb, line 41
      def locate_many(gids, options = {})
        if (allowed_gids = parse_allowed(gids, options[:only])).any?
          locator = locator_for(allowed_gids.first)
          locator.locate_many(allowed_gids, options)
        else
          []
        end
      end

Defined in lib/global_id/locator.rb line 41 · View on GitHub · Improve this page · Find usages on GitHub

Defined in GlobalID::Locator

Type at least 2 characters to search.

↑↓ navigate · open · esc close