# Hanami persistence proposal for 2.x

**URL:** <https://discourse.hanakai.org/t/hanami-persistence-proposal-for-2-x/782>\
**Category:** proposals\
**Created:** [January 18, 2023, 3:13pm UTC](https://discourse.hanakai.org/t/hanami-persistence-proposal-for-2-x/782 "2023-01-18T15:13:02Z")\
**Posts on this page:** 1\
**Showing post:** 7

<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:** [February 1, 2023, 10:48am UTC](https://discourse.hanakai.org/t/hanami-persistence-proposal-for-2-x/782/7 "2023-02-01T10:48:39Z")

</div>

So I’ll comment on this in full soon enough, but in the meantime, I did want to point out one thing.

Over in my example app I’ve just moved my relation classes into `app/`, as a way to start getting a feel for the structure @jodosha has outlined above: [Move relations to app/ by timriley · Pull Request #17 · decafsucks/decafsucks · GitHub](https://github.com/decafsucks/decafsucks/pull/17/files)

This change required I change my rom auto-registration setup to the following:

```ruby
    rom_config.auto_registration(
      target.root.join("app"),
      namespace: Hanami.app.namespace.to_s
    )

```

With `target.root.join("app")` being given as the auto\_registration directory, it means that rom will _also_ look there for `mappers/` and `commands/` subdirectories, as well as the expected `relations/`.

Now defining custom mappers and commands is fairly advanced rom usage, but either way, I don’t think we’d want to see these defined in top-level directories under app. Those directories feel much too prominent for what are otherwise fairly niche concerns.

In addition, there’s a fair chance from naming collisions here too: “mappers” and “commands” are fairly common terms and there’s a non-zero chance that a user will try and create directories like those as the namespace for unrelated objects.

I tried passing this option to rom’s `auto_registration` method:

```auto
component_dirs: {
  relations: :relations
}

```

As well as this:

```auto
component_dirs: {
  relations: relations,
  mappers: nil,
  commands: nil,
}

```

But both of these failed because rom’s auto-registration setup expects these to be defined at all times.

I think this points to the need for rom’s auto-registration setup to be a little more flexible. Ideally I think we’d want the following:

1. Ability to auto-register relations _only_ in with one given root dir (`app/`) and namespace (e.g. `"AppNamespace::Relations"`)
2. And then to _separately_ auto-register mappers and commands with _different_ given root dir and namespace

Implicit in the above is that any for any single rom `auto_registration` call, it should be possible to disable registration for particular component types, such as mappers and commends.

Then after this, as a separate matter, we’d want to think about how whether we want to support default auto-registration for rom mappers and commands within Hanami apps, and if so, what directories they should use.

I suppose an alternative for Hanami’s rom setup could be to avoid rom’s `auto_register` entirely, and instead find and manually register all the rom components. But it’d probably be nice if we could make rom’s `auto_register` more flexible anyway 🙂

cc @solnic since I think these could be useful things to solve with the upcoming version of rom.

---

_[View the full topic](https://discourse.hanakai.org/t/hanami-persistence-proposal-for-2-x/782)._
