Module: Cequel::Record::Callbacks

Extended by:
ActiveSupport::Concern
Defined in:
lib/cequel/record/callbacks.rb

Overview

Cequel::Record models provide lifecycle callbacks for ‘create`, `update`, `save`, `destroy`, and `validation`.

Examples:

class User
  include Cequel::Record

  key :login, :text
  column :name, :text

  after_create :send_welcome_email
  after_update :reindex_posts_for_search
  after_save :reindex_for_search
  after_destroy :send_farewell_email
  before_validation :set_permalink
end

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#destroy(options = {}) ⇒ Record

Remove this record from the database

Parameters:

  • options (Options) (defaults to: {})

    options for deletion

Options Hash (options):

  • :consistency (Symbol)

    what consistency with which to persist the deletion

  • :timestamp (Time)

    the writetime to use for the deletion

Returns:



40
41
42
43
44
# File 'lib/cequel/record/callbacks.rb', line 40

def destroy(options = {})
  connection.batch(options.slice(:consistency)) do
    run_callbacks(:destroy) { super }
  end
end

#save(options = {}) ⇒ Boolean

Persist the record to the database. If this is a new record, it will be saved using an INSERT statement. If it is an existing record, it will be persisted using a series of ‘UPDATE` and `DELETE` statements which will persist all changes to the database, including atomic collection modifications.

Parameters:

  • options (Options) (defaults to: {})

    options for save

Options Hash (options):

  • :validate (Boolean) — default: true

    whether to run validations before saving

  • :consistency (Symbol)

    what consistency with which to persist the changes

  • :ttl (Integer)

    time-to-live of the updated rows in seconds

  • :timestamp (Time)

    the writetime to use for the column updates

Returns:

  • (Boolean)

    true if record saved successfully, false if invalid

See Also:



33
34
35
36
37
# File 'lib/cequel/record/callbacks.rb', line 33

def save(options = {})
  connection.batch(options.slice(:consistency)) do
    run_callbacks(:save) { super }
  end
end