Class | DataMapper::Collection |
In: |
lib/dm-core/collection.rb
|
Parent: | LazyArray |
query | [R] |
Further refines a collection‘s conditions. all provides an interface which simulates a database view.
@param [Hash[Symbol, Object], DataMapper::Query] query parameters for
an query within the results of the original query.
@return [DataMapper::Collection] a collection whose query is the result
of a merge
@api public
Simulates Array#at and returns the entry at that index. Also accepts negative indexes and appropriate reverses the order of the query
@calls Collection#first @calls Collection#last
@api public
default values to use when creating a Resource within the Collection
@return [Hash] The default attributes for DataMapper::Collection#create
@see DataMapper::Collection#create
@api public
batch destroy the entries belongs to this collection, and skip validations for all resources.
@example The War On Terror (if only it were this easy)
Person.all(:terrorist => true).destroy() #
@return [TrueClass, FalseClass]
TrueClass indicates that all entries were affected FalseClass indicates that some entries were affected
@api public
Simulates Array#first by returning the first entry (when there are no arguments), or transforms the collection‘s query by applying :limit => n when you supply an Integer. If you provide a conditions hash, or a Query object, the internal query is scoped and a new collection is returned
@param [Integer, Hash[Symbol, Object], Query] args
@return [DataMapper::Resource, DataMapper::Collection] The
first resource in the entries of this collection, or a new collection whose query has been merged
@api public
retrieves an entry out of the collection‘s entry by key
@param [DataMapper::Types::*, …] key keys which uniquely
identify a resource in the collection
@return [DataMapper::Resource, NilClass] the resource which
has the supplied keys
@api public
retrieves an entry out of the collection‘s entry by key, raising an exception if the object cannot be found
@param [DataMapper::Types::*, …] key keys which uniquely
identify a resource in the collection
@calls DataMapper::Collection#get
@raise [ObjectNotFoundError] "Could not find #{model.name} with key #{key.inspect} in collection"
@api public
Simulates Array#last by returning the last entry (when there are no arguments), or transforming the collection‘s query by reversing the declared order, and applying :limit => n when you supply an Integer. If you supply a conditions hash, or a Query object, the internal query is scoped and a new collection is returned
@calls Collection#first
@api public
reloads the entries associated with this collection
@param [DataMapper::Query] query (optional) additional query
to scope by. Use this if you want to query a collections result set
@see DataMapper::Collection#all
@api public
check to see if collection can respond to the method
@param method [Symbol] method to check in the object @param include_private [FalseClass, TrueClass] if set to true,
collection will check private methods
@return [TrueClass, FalseClass]
TrueClass indicates the method can be responded to by the collection FalseClass indicates the method can not be responded to by the collection
@api public
@return [DataMapper::Collection] a new collection whose
query is sorted in the reverse
@see Array#reverse, DataMapper#all, DataMapper::Query#reverse
@api public
Simulates Array#slice and returns a new Collection whose query has a new offset or limit according to the arguments provided.
If you provide a range, the min is used as the offset and the max minues the offset is used as the limit.
@param [Integer, Array(Integer), Range] args the offset, offset and limit, or range indicating offsets and limits
@return [DataMapper::Resource, DataMapper::Collection]
The entry which resides at that offset and limit, or a new Collection object with the set limits and offset
@raise [ArgumentError] "arguments may be 1 or 2 Integers,
or 1 Range object, was: #{args.inspect}"
@alias []
@api public
batch updates the entries belongs to this collection, and skip validations for all resources.
@example Reached the Age of Alchohol Consumption
Person.all(:age.gte => 21).update!(:allow_beer => true)
@param attributes Hash[Symbol => Object] attributes to update @param reload [FalseClass, TrueClass] if set to true, collection
will have loaded resources reflect updates.
@return [TrueClass, FalseClass]
TrueClass indicates that all entries were affected FalseClass indicates that some entries were affected
@api public