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