> 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/get-an-empty-activerecord-relation.md).

# Get An Empty ActiveRecord Relation

When you query for something (with `#where`) and there are no results matching that query, you get something that looks like an empty array (`[]`), but it's not quite.

```ruby
> result
[]
> result.class
Book::ActiveRecord_Relation
```

It's an empty [`ActiveRecord` relation](https://api.rubyonrails.org/classes/ActiveRecord/Relation.html).

You can get an instance of an empty `ActiveRecord` relation without constructing a *no result* query.

```ruby
> Book.none
[]
> Book.none.class
Book::ActiveRecord_Relation
```

I can think of a couple scenarios where this would be useful:

* as a default value for a method parameter
* as a test value for a method that expects to have an `ActiveRecord` relation passed in

[source](https://stackoverflow.com/questions/4877931/how-to-return-an-empty-activerecord-relation)


---

# 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/get-an-empty-activerecord-relation.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.
