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

#destroyBoolean

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:



37
38
39
# File 'lib/cequel/record/callbacks.rb', line 37

def destroy
  connection.batch { run_callbacks(:destroy) { super }}
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

Returns:

  • (Boolean)

    true if record saved successfully, false if invalid

See Also:



32
33
34
# File 'lib/cequel/record/callbacks.rb', line 32

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