Relation doesn't exist in ROM::RelationRegistry registry

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

Help???

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), but the final release (and the full set of corresponding docs) will be a month or two away.

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

[

Configure ROM from scratch

Hanami Mastery - 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)

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

1 Like

Welcome, @joeradtke

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:

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

Whereas, later in your example you have

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

# 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.

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

Its a rough road but Iā€™m slowly progressing.

| alassek
July 22 |

  • | - |

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:

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ā€™

# 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.

@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!

Iā€™m looking forward to it

Yahoo Mail: Search, Organize, Conquer