module Cequel::Record
Cequel::Record
is an active record-style data modeling library and object-row mapper. Model classes inherit from Cequel::Record
, define their columns in the class definition, and have access to a full and robust set of read and write functionality.
Individual components are documented in their respective modules. See below for links.
@example A Record
class showing off many of the possibilities
class Post include Cequel::Record belongs_to :blog key :id, :timeuuid, auto: true column :title, :text column :body, :text column :author_id, :uuid, index: true set :categories has_many :comments, dependent: destroy after_create :notify_followers validates :title, presence: true def self.for_author(author_id) where(:author_id, author_id) end end
@see Properties
Defining properties @see Collection
Collection
columns @see Associations
Defining associations between records @see Persistence
Creating, updating, and destroying records @see BulkWrites
Updating and destroying records in bulk @see RecordSet
Loading records from the database @see Finders
Magic finder methods @see MassAssignment
Mass-assignment protection and strong attributes @see Callbacks
Lifecycle hooks @see Validations
@see Dirty
Dirty
attribute tracking
Constants
- DangerousQueryError
Raised when attempting to perform a query that has detrimental effects. Typically when trying to count records.
- IllegalQuery
Raised when attempting to construct a {RecordSet} that cannot construct a valid CQL query
@since 1.0.0
- InvalidRecordConfiguration
Raised when attempting to configure a record in a way that is not possible
@since 1.0.0
- MissingAttributeError
Raised when attempting to access an attribute of a record when that attribute hasn't been loaded
@since 1.0.0
- MissingKeyError
Raised when attempting to persist a
Cequel::Record
without defining all primary key columns@since 1.0.0
- MissingTableNameError
Raised when attempting to reflect on the schema of a
Cequel::Record
without a table name.- RecordInvalid
Raised when attempting to save a record that is invalid
- RecordNotFound
Raised when attempting to load a record by key when that record does not exist
- UnknownAttributeError
Raised when attempting to read or write an attribute that isn't defined on the record
@since 1.0.0
Attributes
@return [Metal::Keyspace] the keyspace used for record persistence
Public Class Methods
@return [Array<Class>] All the record classes that are
currently defined.
# File lib/cequel/record.rb, line 123 def descendants weak_descendants.map do |clazz| begin clazz.__getobj__ if clazz.weakref_alive? rescue WeakRef::RefError nil end end.compact end
Establish a connection with the given configuration
@param (see Cequel.connect
) @option (see Cequel.connect
) @return [void]
# File lib/cequel/record.rb, line 117 def establish_connection(configuration) self.connection = Cequel.connect(configuration) end
This is probably not the method you are looking for.
Clear descendants list. Useful in tests to ensure bogus record classes are not synced.
# File lib/cequel/record.rb, line 142 def forget_all_descendants! weak_descendants.clear end
Hook called when new record classes are created.
# File lib/cequel/record.rb, line 134 def included(base) weak_descendants << WeakRef.new(base) end
Private Class Methods
# File lib/cequel/record.rb, line 148 def weak_descendants @weak_descendants ||= [] end