module Cequel::Record::Persistence::ClassMethods

Class-level functionality for loading and saving records

Public Instance Methods

create(attributes = {}, &block) click to toggle source

Initialize a new record instance, assign attributes, and immediately save it.

@param attributes [Hash] attributes to assign to the new record @yieldparam record [Record] record to make modifications before

saving

@return [Record] self

@example Create a new record with attribute assignment

Post.create(
  blog_subdomain: 'cassandra',
  permalink: 'cequel',
  title: 'Cequel: The Next Generation'
)

@example Create a new record with a block

Post.create do |post|
  post.blog = blog
  post.permalink = 'cequel'
  post.title = 'Cequel: The Next Generation'
end
# File lib/cequel/record/persistence.rb, line 45
def create(attributes = {}, &block)
  new(attributes, &block).tap { |record| record.save }
end
hydrate(row) click to toggle source

@return [Cequel::Record] a new instance of this record class populated with the attributes from `row`

@param row [Hash] attributes from the database with which

the new instance should be populated.

@private

# File lib/cequel/record/persistence.rb, line 61
def hydrate(row)
  new_empty.hydrate(row)
end
table() click to toggle source

@private

# File lib/cequel/record/persistence.rb, line 50
def table
  connection[table_name]
end