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.cr

Macro Summary

Macro Detail

macro after_commit(*names, **kwargs) #

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]

[View source]
macro after_create(*names) #

Allows to do define callbacks that are called after creating a model record.


[View source]
macro after_create_commit(*names) #

Allows to define callbacks that are called after a DB commit when a record is created.


[View source]
macro after_create_rollback(*names) #

Allows to define callbacks that are called after a DB rollback when a record is created.


[View source]
macro after_delete(*names) #

Allows to do define callbacks that are called after deleting a model record.


[View source]
macro after_delete_commit(*names) #

Allows to define callbacks that are called after a DB commit when a record is deleted.


[View source]
macro after_delete_rollback(*names) #

Allows to define callbacks that are called after a DB rollback when a record is deleted.


[View source]
macro after_initialize(*names) #

Allows to do define callbacks that are called after initializing a model record.


[View source]
macro after_rollback(*names, **kwargs) #

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]

[View source]
macro after_save(*names) #

Allows to do define callbacks that are called after saving a model record (creation or update).


[View source]
macro after_save_commit(*names) #

Allows to define callbacks that are called after a DB commit when a record is created or updated.


[View source]
macro after_save_rollback(*names) #

Allows to define callbacks that are called after a DB rollback when a record is created or updated.


[View source]
macro after_update(*names) #

Allows to do define callbacks that are called after updating a model record.


[View source]
macro after_update_commit(*names) #

Allows to define callbacks that are called after a DB commit when a record is updated.


[View source]
macro after_update_rollback(*names) #

Allows to define callbacks that are called after a DB rollback when a record is updated.


[View source]
macro before_create(*names) #

Allows to do define callbacks that are called before creating a model record.


[View source]
macro before_delete(*names) #

Allows to do define callbacks that are called before deleting a model record.


[View source]
macro before_save(*names) #

Allows to do define callbacks that are called before saving a model record (creation or update).


[View source]
macro before_update(*names) #

Allows to do define callbacks that are called before updating a model record.


[View source]