> 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/querying/the-collection-object/fetching-the-query/model-attributes.md).

# Model extra attributes

In some case you may want to access a column which is not owned by the model itself. This can be provided by access `attributes` hash on the model.\
In this case, you should set the optional argument `fetch_columns` to `true` during the fetching:

In the example below, we want to display a the identification document `type` and `number` for each person:

```ruby
People.query.left_join("identification_documents"){ 
    peoples.id == identification_documents.person_id
}.select(
    "people.*", 
    "identification_documents.type AS doc_type",
    "identification_documents.number AS doc_number"
).each(fetch_columns: true) do |x|
    puts "Person #{x.full_name}: " +
         "#{x.attributes["doc_type"]} - #{x.attributes["doc_number"]}"
end
```

The optional parameter fetch\_columns is available in most of the methods where we fetch to one or multiple models.

{% hint style="info" %}
`fetch_columns` reduces slightly the performance of the ORM, and that's why it's set to `false` by default.
{% endhint %}

This can be combined also with aggregate functions access, like counter:

```ruby
customers = Customer.query
    .join("shippings"){ shippings.customer_id == customer.id  }
    .select("customers.*", "COUNT(shippings.*) as shipping_count")

customers.each(fetch_columns: true) do |x|
    puts "customer #{x.id} => #{x.attributes["shipping_count"]}"
end
```


---

# 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://clear.gitbook.io/project/querying/the-collection-object/fetching-the-query/model-attributes.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.
