Class: Cuprum::Rails::Commands::FindMany

Inherits:
Cuprum::Rails::Command show all
Includes:
Collections::Commands::AbstractFindMany
Defined in:
lib/cuprum/rails/commands/find_many.rb

Overview

Command for finding multiple ActiveRecord records by primary key.

Instance Attribute Summary

Attributes inherited from Cuprum::Rails::Command

#collection_name, #member_name, #options, #record_class

Instance Method Summary collapse

Methods inherited from Cuprum::Rails::Command

#initialize, #primary_key_name, #primary_key_type, subclass

Constructor Details

This class inherits a constructor from Cuprum::Rails::Command

Instance Method Details

#call(primary_keys: , allow_partial: false, envelope: false, scope: nil) ⇒ Cuprum::Result<Array<ActiveRecord>>

Queries the collection for the records with the given primary keys.

The command will find and return the entities with the given primary keys. If any of the records are not found, the command will fail and return a NotFound error. If the :allow_partial option is set, the command will return a partial result unless none of the requested records are found.

When the :envelope option is true, the command wraps the records in a Hash, using the name of the collection as the key.

Parameters:

  • allow_partial (Boolean) (defaults to: false)

    If true, passes if any of the records are found.

  • envelope (Boolean) (defaults to: false)

    If true, wraps the result value in a Hash.

  • primary_keys (Array) (defaults to: )

    The primary keys of the requested records.

  • scope (Cuprum::Collections::Basic::Query, nil) (defaults to: nil)

    Optional scope for the query. Records must match the scope as well as the primary keys.

Returns:

  • (Cuprum::Result<Array<ActiveRecord>>)

    a result with the requested records.



37
38
39
40
41
42
# File 'lib/cuprum/rails/commands/find_many.rb', line 37

validate_parameters :call do
  keyword :allow_partial, Stannum::Constraints::Boolean.new, default: true
  keyword :envelope,      Stannum::Constraints::Boolean.new, default: true
  keyword :primary_keys,  Array
  keyword :scope,         Cuprum::Rails::Query, optional: true
end