Method: DataMapper::Collection#all
- Defined in:
- lib/dm-core/collection.rb
#all(query = Undefined) ⇒ Collection
Returns a new Collection optionally scoped by query
This returns a new Collection scoped relative to the current Collection.
cars_from_91 = Cars.all(:year_manufactured => 1991)
toyotas_91 = cars_from_91.all(:manufacturer => 'Toyota')
toyotas_91.all? { |car| car.year_manufactured == 1991 }       #=> true
toyotas_91.all? { |car| car.manufacturer == 'Toyota' }        #=> true
If query is a Hash, results will be found by merging query with this Collection’s query. If query is a Query, results will be found using query as an absolute query.
| 213 214 215 216 217 218 219 220 221 | # File 'lib/dm-core/collection.rb', line 213 def all(query = Undefined) if query.equal?(Undefined) || (query.kind_of?(Hash) && query.empty?) dup else # TODO: if there is no order parameter, and the Collection is not loaded # check to see if the query can be satisfied by the head/tail new_collection(scoped_query(query)) end end |