# Has one through association

**URL:** <https://discourse.rom-rb.org/t/has-one-through-association/404>\
**Category:** Issues\
**Created:** [December 10, 2020, 10:38am UTC](https://discourse.rom-rb.org/t/has-one-through-association/404 "2020-12-10T10:38:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![klotz.dabril](https://avatars.discourse-cdn.com/v4/letter/k/4da419/32.png) [@klotz.dabril](https://discourse.rom-rb.org/u/klotz.dabril)\
**Post date:** [December 10, 2020, 10:38am UTC](https://discourse.rom-rb.org/t/has-one-through-association/404/1 "2020-12-10T10:38:04Z")

</div>

Hi, i’m trying to make these associations work but I can’t figure out what’s wrong. The has\_one through association in the orders relation gives me the error `KeyError: :order_id attribute doesn't exist in contracts schema` and that’s right, it doesn’t, the foreign key is in the orders table. Could anyone point me to right path?

```ruby
class Orders < ROM::Relation[:sql]
  schema(:orders, infer: true) do
    associations do
      belongs_to :contract
      has_one :organization, through: :contracts
    end
  end
end

class Contracts < ROM::Relation[:sql]
  schema(:contracts, infer: true) do
    associations do
      belongs_to :organization
      has_many :orders
    end
  end
end

class Organizations < ROM::Relation[:sql]
  schema(:organizations, infer: true) do
    associations do
      has_many :contracts
    end
  end
end

```
