# Relation doesn't exist in ROM::RelationRegistry registry

**URL:** <https://discourse.hanakai.org/t/relation-doesnt-exist-in-rom-relationregistry-registry/999>\
**Category:** questions\
**Created:** [July 20, 2024, 7:56pm UTC](https://discourse.hanakai.org/t/relation-doesnt-exist-in-rom-relationregistry-registry/999 "2024-07-20T19:56:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![joeradtke](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/joeradtke/32/744_2.png) [@joeradtke](https://discourse.hanakai.org/u/joeradtke)\
**Post date:** [July 20, 2024, 7:56pm UTC](https://discourse.hanakai.org/t/relation-doesnt-exist-in-rom-relationregistry-registry/999/1 "2024-07-20T19:56:52Z")

</div>

How in the world do you register a relation. None of the docs that I can find deal with this

Help???

---

<div class="post-metadata">

**Author:** ![timriley](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/timriley/32/621_2.png) [@timriley](https://discourse.hanakai.org/u/timriley)\
**Post date:** [July 21, 2024, 10:42am UTC](https://discourse.hanakai.org/t/relation-doesnt-exist-in-rom-relationregistry-registry/999/2 "2024-07-21T10:42:16Z")

</div>

Hi @joeradtke, thanks for using Hanami!

We’ll need some more information to help you here. For example:

- What version of Hanami are you using?
- How are you currently configuring ROM?
- What instructions did you follow to get started with ROM?
- Where are you putting your relation files?

If you can share a full reproduction of this issue (e.g. a Hanami app using same versions and same ROM setup as you have in your app), that would help us help you.

I should note that Hanami 2 does not currently have dedicated docs about registering ROM relations because Hanami 2 has not yet had a release with a first-party database layer. This is coming soon as part of version 2.2 (we [just released a beta](https://hanamirb.org/blog/2024/07/16/hanami-220beta1/)), but the final release (and the full set of corresponding docs) will be a month or two away.

---

<div class="post-metadata">

**Author:** ![joeradtke](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/joeradtke/32/744_2.png) [@joeradtke](https://discourse.hanakai.org/u/joeradtke)\
**Post date:** [July 21, 2024, 11:35pm UTC](https://discourse.hanakai.org/t/relation-doesnt-exist-in-rom-relationregistry-registry/999/3 "2024-07-21T23:35:14Z")

</div>

Hanami 2.1

Hanami.app.register\_provider :persistence, namespace: true do  
prepare do  
require “rom”  
require ‘rom-changeset’  
require ‘rom/core’  
require ‘rom/sql’

config = ROM::Configuration.new(:sql, target[“settings”].database\_url)  
config.relation(:users)  
register “config”, config  
register “db”, config.gateways[:default].connection  
end

start do  
config = target[“persistence.config”]

config.auto\_registration(  
target.root.join(“lib/trial3/persistence”),  
namespace: “Trial3::Persistence”  
)

register “rom”, ROM.container(config)  
end  
end

[Configure ROM from scratch](https://hanamimastery.com/episodes/28-configure-rom-from-scratch)

[

## Configure ROM from scratch

Hanami Mastery - [https://hanamimastery.com](https://hanamimastery.com)  
Hanami 2.0 comes without the persistence layer nor views preconfigured. It is useful then to know how to set up …  
]([Configure ROM from scratch | Hanami Mastery](https://hanamimastery.com/episodes/28-configure-rom-from-scratch))

relation files in lib/appname/persistence/relations

After another day of experimenting I finally got it to work but I’m not sure what I did.

There’s a steep learning curve with hanami but I’m getting there. It’s a challenge but quite satisfying.

Joe

---

<div class="post-metadata">

**Author:** ![alassek](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/alassek/32/532_2.png) [@alassek](https://discourse.hanakai.org/u/alassek)\
**Post date:** [July 22, 2024, 6:18pm UTC](https://discourse.hanakai.org/t/relation-doesnt-exist-in-rom-relationregistry-registry/999/4 "2024-07-22T18:18:28Z")

</div>

Welcome, @joeradtke

> [@joeradtke](#):
>
> config.relation(:users)

I believe this might be the problem. You can either automatically register relations by convention, or you can manually register them, but you have to choose one or the other.

`config.relation` is for manual registration, such as:

```ruby
config.relation :users do
  schema :users, infer: true
end

```

Whereas, later in your example you have

> [@joeradtke](#):
>
> config.auto\_registration(  
> target.root.join(“lib/trial3/persistence”),  
> namespace: “Trial3::Persistence”  
> )

This indicates to me that you should have class-based relations located in `lib/trial3/persistence’

```ruby
# lib/trial3/persistence/relations/users.rb

module Trial3
  module Persistence
    module Relations
      class Users < ROM::Relation[:sql]
        schema :users, infer: true
      end
    end
  end
end

```

I suggest removing `config.relation(:users)` and seeing if that helps, however I will echo Tim’s advice and say that the 2.2 release will make this _substantially_ easier to setup.

---

<div class="post-metadata">

**Author:** ![joeradtke](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/joeradtke/32/744_2.png) [@joeradtke](https://discourse.hanakai.org/u/joeradtke)\
**Post date:** [July 22, 2024, 6:38pm UTC](https://discourse.hanakai.org/t/relation-doesnt-exist-in-rom-relationregistry-registry/999/5 "2024-07-22T18:38:54Z")

</div>

Actually adding config.relation(:users) is what fixed it.

Its a rough road but I’m slowly progressing.

> ![](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanamirb.org/alassek/45/532_2.png "alassek") | [alassek](https://discourse.hanakai.org/u/alassek)  
> July 22 |
> 
> - | - |

Welcome, [@joeradtke](https://discourse.hanakai.org/u/joeradtke)

> ![](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanamirb.org/joeradtke/48/744_2.png)joeradtke:
> 
> config.relation(:users)

I believe this might be the problem. You can either automatically register relations by convention, or you can manually register them, but you have to choose one or the other.

`config.relation` is for manual registration, such as:

```auto
config.relation :users do
  schema :users, infer: true
end

```

Whereas, later in your example you have

> ![](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanamirb.org/joeradtke/48/744_2.png)joeradtke:
> 
> config.auto\_registration(  
> target.root.join(“lib/trial3/persistence”),  
> namespace: “Trial3::Persistence”  
> )

This indicates to me that you should have class-based relations located in `lib/trial3/persistence’

```auto
# lib/trial3/persistence/users.rb

module Trial3
  module Persistence
    class Users < ROM::Relation[:sql]
      schema :users, infer: true
    end
  end
end

```

I suggest removing `config.relation(:users)` and seeing if that helps, however I will echo Tim’s advice and say that the 2.2 release will make this _substantially_ easier to setup.

---

<div class="post-metadata">

**Author:** ![swilgosz](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/swilgosz/32/484_2.png) [@swilgosz](https://discourse.hanakai.org/u/swilgosz)\
**Post date:** [July 24, 2024, 8:08pm UTC](https://discourse.hanakai.org/t/relation-doesnt-exist-in-rom-relationregistry-registry/999/6 "2024-07-24T20:08:52Z")

</div>

@joeradtke Yeah, after 2.2 release I’ll also launch more up to date tutorial series on HanamiMastery, I hope the overall experience will be on the next-level and whole configuration will be significantly easier.

Thanks for bringing it in!

---

<div class="post-metadata">

**Author:** ![joeradtke](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.hanakai.org/joeradtke/32/744_2.png) [@joeradtke](https://discourse.hanakai.org/u/joeradtke)\
**Post date:** [July 24, 2024, 9:16pm UTC](https://discourse.hanakai.org/t/relation-doesnt-exist-in-rom-relationregistry-registry/999/7 "2024-07-24T21:16:42Z")

</div>

I’m looking forward to it

[Yahoo Mail: Search, Organize, Conquer](https://mail.onelink.me/107872968?pid=NativePlacement&c=Global_Acquisition_YMktg_315_EmailSignatureGrowth_YahooMail:Search,Organize,Conquer&af_sub1=Acquisition&af_sub2=Global_YMktg&af_sub3=&af_sub4=100000945&af_sub5=OrganizeConquer__Static_)
