# Is rom-factory compatible with hamami?

**URL:** <https://discourse.rom-rb.org/t/is-rom-factory-compatible-with-hamami/663>\
**Category:** Issues\
**Created:** [November 15, 2024, 2:40pm UTC](https://discourse.rom-rb.org/t/is-rom-factory-compatible-with-hamami/663 "2024-11-15T14:40:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vladimirtcats](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/vladimirtcats/32/330_2.png) [@vladimirtcats](https://discourse.rom-rb.org/u/vladimirtcats)\
**Post date:** [November 15, 2024, 2:40pm UTC](https://discourse.rom-rb.org/t/is-rom-factory-compatible-with-hamami/663/1 "2024-11-15T14:40:37Z")

</div>

Hi everyone

I am trying to config rom-factory.

I have created app and put provider

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

```
config =
  ROM::Configuration.new(
    :sql, target['settings'].database_url
  )

register 'config', config
register 'db', config.gateways[:default].connection

```

end

start do  
config = target[‘persistence.config’]

```
config.auto_registration(
  target.root.join('relations'),
  namespace: 'MyApp::Relations'
)

register 'rom', ROM.container(config)

```

end  
end

also I configure factory

require “rom-factory”

require “faker”

Factory = ROM::Factory.configure do |config|  
config.rom = MyApp::Container[“persistence.rom”]  
end

Dir[File.dirname( **FILE** ) + “/factories/\*.rb”].each { |file| require file }

and created factory

Factory.define(:users) do |f|  
f.sequence(:name) { |n| “name #{n}” }  
end

but I got error

ROM::ElementNotFoundError:  
:users doesn’t exist in ROM::RelationRegistry registry

Could you give me information how to config rom-factory correctly?

---

<div class="post-metadata">

**Author:** ![bkuhlmann](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/bkuhlmann/32/280_2.png) [@bkuhlmann](https://discourse.rom-rb.org/u/bkuhlmann)\
**Post date:** [November 15, 2024, 3:39pm UTC](https://discourse.rom-rb.org/t/is-rom-factory-compatible-with-hamami/663/2 "2024-11-15T15:39:15Z")

</div>

Hey Vladimir, are you using Hanami 2.2.0? I ask because setup in Hanami 2.1.0 was complicated but with 2.2.0 the [Hanami DB](https://github.com/hanami/db) gem is installed by default for you so you don’t need to do any of this because you can simply [require ROM factory](https://github.com/bkuhlmann/hemo/blob/main/spec/hanami_helper.rb#L8). In fact, that link is a working example as generated for you when building a new Hanami app using [Hanamismith](https://alchemists.io/projects/hanamismith).

If you do that, you should be up and running in no time.

---

<div class="post-metadata">

**Author:** ![vladimirtcats](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/vladimirtcats/32/330_2.png) [@vladimirtcats](https://discourse.rom-rb.org/u/vladimirtcats)\
**Post date:** [November 16, 2024, 6:36am UTC](https://discourse.rom-rb.org/t/is-rom-factory-compatible-with-hamami/663/3 "2024-11-16T06:36:51Z")

</div>

Hey @bkuhlmann  
I use hanami 2.2.0.

**I have several questions:**

1. Should I register separated provider for working with db?
2. How to correctly register hanami relations with rom-factory?

I will check your link later. Thank you!

---

<div class="post-metadata">

**Author:** ![bkuhlmann](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/bkuhlmann/32/280_2.png) [@bkuhlmann](https://discourse.rom-rb.org/u/bkuhlmann)\
**Post date:** [November 16, 2024, 3:48pm UTC](https://discourse.rom-rb.org/t/is-rom-factory-compatible-with-hamami/663/4 "2024-11-16T15:48:13Z")

</div>

To answer:

1. So that’s what I’m saying, you don’t need a ROM Factory provider at all. You’ll have what you need via the Hanami DB gem that is part of Hanami 2.2.0.
2. Setting up and using relations is documented [here](https://guides.hanamirb.org/v2.2/database/relations).

---

<div class="post-metadata">

**Author:** ![vladimirtcats](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/vladimirtcats/32/330_2.png) [@vladimirtcats](https://discourse.rom-rb.org/u/vladimirtcats)\
**Post date:** [November 18, 2024, 5:22am UTC](https://discourse.rom-rb.org/t/is-rom-factory-compatible-with-hamami/663/5 "2024-11-18T05:22:49Z")

</div>

Brooke, thank you for your help!

Also I got my mistake

While configuring container I had to use

```ruby
MyApp::Container["db.rom"]

```

instead of

```ruby
MyApp::Container[“persistence.rom”]

```

---

<div class="post-metadata">

**Author:** ![alassek](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/alassek/32/260_2.png) [@alassek](https://discourse.rom-rb.org/u/alassek)\
**Post date:** [November 18, 2024, 7:56pm UTC](https://discourse.rom-rb.org/t/is-rom-factory-compatible-with-hamami/663/6 "2024-11-18T19:56:57Z")

</div>

`ROM::Factory` integration didn’t get done in time for Hanami 2.2, but that will likely be released in the near future as a follow-on. In the meantime you have to do some manual configuration but that will be streamlined.
