Class: DatastaxRails::WideStorageModel

Inherits:
Base show all
Defined in:
lib/datastax_rails/wide_storage_model.rb

Overview

A special model that is designed to efficiently store very wide data. This model type assumes that you have a unique ID that you want to store a lot of data about. The data is stored as a single, very wide row; however you can safely treat it as if there were multiple rows. A common example of this is a logs table

You can also apply secondary indexes onto the other columns.

CAVEATS:

  • Once the cluster attribute is set, it cannot be changed as it becomes the column header in Cassandra

    class AuditLog < DatastaxRails::WideStorageModel

    self.column_family = 'audit_logs'
    self.primary_key = :uuid
    self.cluster_by = :created_at
    # If you don't want the default ascending sort order
    self.create_options = 'CLUSTERING ORDER BY (created_at DESC)'
    
    string :uuid
    string :message
    string :user_id, :cql_index => true
    timestamps
    

    end

Direct Known Subclasses

DynamicModel, PayloadModel

Constant Summary

Constants included from Callbacks

Callbacks::CALLBACKS

Instance Attribute Summary

Attributes inherited from Base

#attributes, #key, #loaded_attributes

Attributes included from Associations

#association_cache

Instance Method Summary collapse

Methods inherited from Base

#==, #attribute_names, attribute_names, base_class, #column_names, columns, default_page_size, #eql?, find_by_id, #freeze, #frozen?, #hash, #init_changed_attributes, #init_internals, #init_with, #initialize, inspect, legacy_mapping?, logger, models, payload_model?, search_ids, #to_param, valid_consistency?, #valid_consistency?, wide_storage_model?

Methods included from SolrRepair

#repair_solr

Methods included from Serialization

#as_json, #serializable_hash, #to_xml

Methods included from Timestamps

#initialize_dup

Methods included from Scoping

#populate_with_current_scope_attributes

Methods included from Associations

#association, #clear_association_cache

Methods included from Callbacks

#destroy

Methods included from Validations

#save, #save!, #valid?

Methods included from AttributeMethods

#attribute_exists?, #column_for_attribute, #method_missing, #respond_to?

Methods included from AttributeAssignment

#assign_attributes

Methods included from Batches

#find_each, #find_each_with_index, #find_in_batches

Methods included from FinderMethods

#find, #find_by, #find_by!, #first, #first!, #last, #last!

Methods included from Persistence

#destroy, #persisted?, #reload, #save, #save!, #toggle, #toggle!, #update_attribute, #update_attributes, #update_attributes!

Constructor Details

This class inherits a constructor from DatastaxRails::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class DatastaxRails::AttributeMethods

Instance Method Details

#id_for_updateObject

Returns a primary key hash for updates that includes the cluster key



29
30
31
# File 'lib/datastax_rails/wide_storage_model.rb', line 29

def id_for_update
  { self.class.primary_key.to_s => id, self.class.cluster_by.to_s => read_attribute(self.class.cluster_by.to_s) }
end