> For the complete documentation index, see [llms.txt](https://kelby.gitbook.io/rails-beginner-s-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kelby.gitbook.io/rails-beginner-s-guide/activerecord_db_opertion.md).

# Active Record 数据库操作：增删查改

Web 应用使用到数据库，而管理数据库使用的是 SQL 语言。我们不需要专门去学习 SQL，只需要用 Ruby 语言，写 Ruby 代码就能实现数据库的相关操作(也就是各种简单、复杂的读写操作)。

* Scoping

包括 Default、Named

* Relation

包括 Spawn Methods、Query Methods、Finder Methods、Calculations、Batches、~~Delegation~~、~~Predicate Builder~~、~~Merger~~

* Querying
* Persistence

即将被废除的 gem 'activerecord-deprecated\_finders'

* Counter Cache
* Attribute Assignment

主要工作由 ActiveModel::AttributeAssignment 完成，这里不再赘述。

* Attribute Methods

包括 Before Type Cast、Dirty、Primary Key、Query、Read & Write、Serialization、Time Zone Conversion

* ~~Null Relation~~
* ~~Dynamic Matchers~~


---

# 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, and the optional `goal` query parameter:

```
GET https://kelby.gitbook.io/rails-beginner-s-guide/activerecord_db_opertion.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
