> For the complete documentation index, see [llms.txt](https://ploegert.gitbook.io/til/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ploegert.gitbook.io/til/programmy/rails/update-column-versus-update-attribute.md).

# Update Column Versus Update Attribute

Rails offers a whole variety of methods for making updates to the ActiveRecord objects in your app. Two unique, infrequently-used ones are [`#update_column`](https://devdocs.io/rails~5.2/activerecord/persistence#method-i-update_column) and [`#update_attribute`](https://devdocs.io/rails~5.2/activerecord/persistence#method-i-update_attribute). What is unique about them is that they are both ways of updating a record while skipping the validations defined on the model.

So, how do they differ?

A call to `#update_attribute` is still going to trigger any callbacks defined on the model and it will touch the `update_at` column. On the other hand, `#update_column` can be thought of as a way of directly interacting with the database -- callbacks are skipped and you are truly only touching the specified column, `updated_at` is left as is.

The docs have this recommendation for `#update_attribute`:

> This is especially useful for boolean flags on existing records.

And for `#update_column`, they say this:

> This is the fastest way to update attributes because it goes straight to the database, but take into account that in consequence the regular update procedures are totally bypassed.

These are both useful in specific situations, but be sure to know their differences and to use them with caution.


---

# 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://ploegert.gitbook.io/til/programmy/rails/update-column-versus-update-attribute.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.
