Class: Cequel::Record::AssociationCollection
- Extended by:
- Forwardable
- Includes:
- Enumerable
- Defined in:
- lib/cequel/record/association_collection.rb
Overview
Instance Attribute Summary
Attributes inherited from RecordSet
Instance Method Summary collapse
-
#count ⇒ Integer
Get the count of child records stored in the database.
- #each {|Record| ... } ⇒ void
-
#find(*keys) ⇒ Record, LazyRecordCollection
Return a loaded Record or collection of loaded Records with the specified primary key values.
- #first(*args) ⇒ Record, Array
-
#length ⇒ Integer
The number of child instances in the in-memory collection.
-
#loaded? ⇒ Boolean
True if this collection’s records are loaded in memory.
- #select(*columns) ⇒ Array, RecordSet
-
#size ⇒ Integer
Get the size of the child collection.
Methods inherited from RecordSet
#==, #[], #after, #all, #assert_fully_specified!, #at, #before, #data_set, default_attributes, #delete_all, #find_each, #find_each_row, #find_in_batches, #find_rows_in_batches, #from, #in, #initialize, #last, #limit, #reverse, #scoped_key_attributes, #upto, #values_at, #where
Methods included from Util::HashAccessors
#hattr_accessor, #hattr_inquirer, #hattr_reader, #hattr_writer
Methods included from BulkWrites
#delete_all, #destroy_all, #update_all
Constructor Details
This class inherits a constructor from Cequel::Record::RecordSet
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Cequel::Record::RecordSet
Instance Method Details
#count ⇒ Integer
Get the count of child records stored in the database. This method will always query Cassandra, even if the records are loaded in memory.
61 |
# File 'lib/cequel/record/association_collection.rb', line 61 def_delegator :record_set, :count |
#each {|Record| ... } ⇒ void
This method returns an undefined value.
20 21 22 |
# File 'lib/cequel/record/association_collection.rb', line 20 def each(&block) target.each(&block) end |
#find(*keys) ⇒ Record, LazyRecordCollection
Return a loaded Record or collection of loaded Records with the specified primary key values
Multiple arguments are mapped onto unscoped key columns. To specify multiple values for a given key column, use an array.
27 28 29 30 31 |
# File 'lib/cequel/record/association_collection.rb', line 27 def find(*keys) if block_given? then super else record_set.find(*keys) end end |
#first ⇒ Record #first(count) ⇒ Array
45 46 47 48 49 |
# File 'lib/cequel/record/association_collection.rb', line 45 def first(*args) if loaded? then super else record_set.first(*args) end end |
#length ⇒ Integer
The number of child instances in the in-memory collection. If the records are not loaded in memory, they will be loaded and then counted.
73 |
# File 'lib/cequel/record/association_collection.rb', line 73 def_delegator :entries, :length |
#loaded? ⇒ Boolean
Returns true if this collection’s records are loaded in memory.
92 93 94 |
# File 'lib/cequel/record/association_collection.rb', line 92 def loaded? !!@target end |
#select {|record| ... } ⇒ Array #select(*columns) ⇒ RecordSet
36 37 38 39 40 |
# File 'lib/cequel/record/association_collection.rb', line 36 def select(*columns) if block_given? then super else record_set.select(*columns) end end |
#size ⇒ Integer
Get the size of the child collection. If the records are loaded in memory from a previous operation, count the length of the array in memory. If the collection is unloaded, perform a ‘COUNT` query.
84 85 86 |
# File 'lib/cequel/record/association_collection.rb', line 84 def size loaded? ? length : count end |