module Marten::DB::Model::Callbacks
Overview
Provides the ability to define model callbacks.
This module provides the ability to define callbacks that are executed before and / or after specific model record operations (ie. initialization, creation, update, save, and deletion).
Direct including types
Defined in:
marten/db/model/callbacks.crMacro Summary
-
after_commit(*names, **kwargs)
Allows to define callbacks that are called after a DB commit when a record is created, updated, or deleted.
-
after_create(*names)
Allows to do define callbacks that are called after creating a model record.
-
after_create_commit(*names)
Allows to define callbacks that are called after a DB commit when a record is created.
-
after_create_rollback(*names)
Allows to define callbacks that are called after a DB rollback when a record is created.
-
after_delete(*names)
Allows to do define callbacks that are called after deleting a model record.
-
after_delete_commit(*names)
Allows to define callbacks that are called after a DB commit when a record is deleted.
-
after_delete_rollback(*names)
Allows to define callbacks that are called after a DB rollback when a record is deleted.
-
after_initialize(*names)
Allows to do define callbacks that are called after initializing a model record.
-
after_rollback(*names, **kwargs)
Allows to define callbacks that are called after a DB rollback when a record is created, updated, or deleted.
-
after_save(*names)
Allows to do define callbacks that are called after saving a model record (creation or update).
-
after_save_commit(*names)
Allows to define callbacks that are called after a DB commit when a record is created or updated.
-
after_save_rollback(*names)
Allows to define callbacks that are called after a DB rollback when a record is created or updated.
-
after_update(*names)
Allows to do define callbacks that are called after updating a model record.
-
after_update_commit(*names)
Allows to define callbacks that are called after a DB commit when a record is updated.
-
after_update_rollback(*names)
Allows to define callbacks that are called after a DB rollback when a record is updated.
-
before_create(*names)
Allows to do define callbacks that are called before creating a model record.
-
before_delete(*names)
Allows to do define callbacks that are called before deleting a model record.
-
before_save(*names)
Allows to do define callbacks that are called before saving a model record (creation or update).
-
before_update(*names)
Allows to do define callbacks that are called before updating a model record.
Macro Detail
Allows to define callbacks that are called after a DB commit when a record is created, updated, or deleted.
By default, the callback method will be called after record creations, updates, and deletions. It is also
possible to restrict the callback to certain actions by using the on
argument as follows:
after_commit :do_something, on: :create # Will run only after creations
after_commit :do_something, on: :update # Will run only after updates
after_commit :do_something, on: :update # Will run only after saves (creations or updates)
after_commit :do_something, on: :delete # Will run only after deletions
The actions supported for the on
argument are create
, update
, save
, and delete
. Note that it is also
possible to define that an after commit callback must run for multiple actions by using an array of actions:
after_commit :do_something, on: [:update, :delete]
Allows to do define callbacks that are called after creating a model record.
Allows to define callbacks that are called after a DB commit when a record is created.
Allows to define callbacks that are called after a DB rollback when a record is created.
Allows to do define callbacks that are called after deleting a model record.
Allows to define callbacks that are called after a DB commit when a record is deleted.
Allows to define callbacks that are called after a DB rollback when a record is deleted.
Allows to do define callbacks that are called after initializing a model record.
Allows to define callbacks that are called after a DB rollback when a record is created, updated, or deleted.
By default, the callback method will be called in the context of record creations, updates, and deletions. It
is also possible to restrict the callback to certain actions by using the on
argument as follows:
after_rollback :do_something, on: :create # Will run only after creations
after_rollback :do_something, on: :update # Will run only after updates
after_rollback :do_something, on: :update # Will run only after saves (creations or updates)
after_rollback :do_something, on: :delete # Will run only after deletions
The actions supported for the on
argument are create
, update
, save
, and delete
. Note that it is also
possible to define that an after rollback callback must run for multiple actions by using an array of actions:
after_rollback :do_something, on: [:update, :delete]
Allows to do define callbacks that are called after saving a model record (creation or update).
Allows to define callbacks that are called after a DB commit when a record is created or updated.
Allows to define callbacks that are called after a DB rollback when a record is created or updated.
Allows to do define callbacks that are called after updating a model record.
Allows to define callbacks that are called after a DB commit when a record is updated.
Allows to define callbacks that are called after a DB rollback when a record is updated.
Allows to do define callbacks that are called before creating a model record.
Allows to do define callbacks that are called before deleting a model record.
Allows to do define callbacks that are called before saving a model record (creation or update).
Allows to do define callbacks that are called before updating a model record.