> For the complete documentation index, see [llms.txt](https://clear.gitbook.io/project/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://clear.gitbook.io/project/model/lifecycle/callbacks.md).

# Triggers

Clear provides a way to create triggers on different time of the lifecycle of the model.

## Example usage

```ruby
class User
    include Clear::Model

    column first_name : String
    column last_name : String

    def full_name
        {first_name, last_name}.join(" ")
    end

    after :create, :send_email

    before(:update) { |m| m.as(User).updated_at = Time.local }

    def send_email
        EmailManager.send_email(subject: "welcome #{full_name} !", body: "...")
    end
end
```

## Caveats

* Calling before/after with a block will return a Clear::Model as argument. Therefore, you must cast the variable (`m.as(User)` in example above).
* `before/after :action, :method` must be pointing to public method. If the method is private, the call will fail.

## Trigger list

| Trigger symbol       | Description                                                                                                                                                              |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `:validate`          | Is triggered before and after calling `valid?` method                                                                                                                    |
| `:save`              | Is triggered before and after calling `save` method                                                                                                                      |
| `:delete`            | Is triggered before and after destroying a model                                                                                                                         |
| `:create`            | Is triggered before and after calling `save` method, if the model is not yet persisted and save execute INSERT request.                                                  |
| `:update`            | Is triggered before and after calling `save` method, if the model is already existing and save execute UPDATE request.                                                   |
| `:creation_commited` | **Note: PLANNED FEATURE NOT YET IMPLEMENTED**. Is triggered when a transaction is commited, for each model which has been created during the lifetime of a transaction   |
| `:update_commited`   | **Note: PLANNED FEATURE NOT YET IMPLEMENTED.** Is triggered when a transaction is commited, for each model which has been updated during the lifetime of a transaction   |
| `:delete_commited`   | **Note: PLANNED FEATURE NOT YET IMPLEMENTED.** Is triggered when a transaction is commited, for each model which has been destroyed during the lifetime of a transaction |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://clear.gitbook.io/project/model/lifecycle/callbacks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
