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 = {}) ⇒ Object

Remove this record from the database

Parameters:

  • options [Options] options for deletion

Returns:

  • Record

    self



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 = {}) ⇒ Object

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] options for save

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