# Best way to load belongs\_to-assocation in one select?

**URL:** <https://discourse.rom-rb.org/t/best-way-to-load-belongs-to-assocation-in-one-select/481>\
**Category:** Issues\
**Created:** [October 7, 2021, 7:07am UTC](https://discourse.rom-rb.org/t/best-way-to-load-belongs-to-assocation-in-one-select/481 "2021-10-07T07:07:18Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wuarmin](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/wuarmin/32/233_2.png) [@wuarmin](https://discourse.rom-rb.org/u/wuarmin)\
**Post date:** [October 7, 2021, 7:07am UTC](https://discourse.rom-rb.org/t/best-way-to-load-belongs-to-assocation-in-one-select/481/1 "2021-10-07T07:07:18Z")

</div>

Hey,  
I love ROM and I am curious about the above question: **What’s the best way to load belongs\_to-assocation in one select?**

```ruby
# states-relation
module Orm
  module Relations
    class States < ROM::Relation[:sql]
      schema(:states, infer: true)
    end
  end
end

```

```ruby
# records-relation
module Orm
  module Relations
    class Records < ROM::Relation[:sql]
      schema(:records, infer: true) do
        associations do
          belongs_to :states, as: :status, foreign_key: :status_id
        end
      end
    end
  end
end

```

Following solution works, but **2 selects are executed**. I think in this case it is more performant to combine the states in one select. Is this possible? With plain-sequel there is **eager\_graph**.

```ruby
# records-repo
module Repositories
  class AiRecordsRepo < ROM::Repository[:records]
    include Import["orm.container"]

    struct_namespace Entities

    def all_with_status
      ai_records.combine(:status).to_a
    end

  end
end

```

Or is the only way I can achieve this the following:

```ruby
    def all_with_status
      ai_records.join(:states).select_append(states[:name]).to_a
    end

```

The disadvantage of the **select\_append** solution is, that the real association is not loaded.

What’s your opinion about that?

**UPDATE** #########################  
I came across ROM:Relation#wrap. It solves my use-case? It is not documented at first glance on the main webpage. Is this a solution you would use? Maybe we should add it to the web-documentation.

```ruby
    def all_with_status
      # ai_records.join(:states).select_append(states[:name]).to_a
      ai_records.wrap(:status).to_a
    end

```

**UPDATE** ########################

Thanks!  
Best regards  
– Armin
