# Just mappers? Upgrading from old 'rom-mapper' use

**URL:** <https://discourse.rom-rb.org/t/just-mappers-upgrading-from-old-rom-mapper-use/601>\
**Category:** Issues\
**Created:** [March 20, 2023, 5:36pm UTC](https://discourse.rom-rb.org/t/just-mappers-upgrading-from-old-rom-mapper-use/601 "2023-03-20T17:36:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![brcarp](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/brcarp/32/294_2.png) [@brcarp](https://discourse.rom-rb.org/u/brcarp)\
**Post date:** [March 20, 2023, 5:36pm UTC](https://discourse.rom-rb.org/t/just-mappers-upgrading-from-old-rom-mapper-use/601/1 "2023-03-20T17:36:57Z")

</div>

I’m reaching out for some advice because I’m not too familiar with ROM and am attempting to upgrade from an older use of the standalone `rom-mapper` gem to do some data mapping, which I suspect was inspired by [this old post by Piotr Solnica](https://solnic.codes/2015/07/15/importing-data-with-rom-and-transproc/).

Basically we have some classes that inherit from `ROM::Mapper` and the application is calling `build`/`call` on these in different ways. The application is using the latest available version of the `rom-mapper` gem where it can function standalone (0.5.1), but any version above that requires integration with `rom` (because it’s looking for `rom/constants` at a minimum).

I’d like to migrate this from using `rom-mapper` to using `rom`, but the upgrade guides don’t address this particular use case so I’m wondering how to proceed. Is it as simple as adding `rom` and continuing to use the `ROM::Mapper` inheritances because that class still exists? Or should I be trying to use `ROM::Transformer` or `ROM::Relation` instead, and what level of context is required to update the application to adhere to modern expectations of ROM?

Thanks for your help!

---

<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:** [March 21, 2023, 7:18pm UTC](https://discourse.rom-rb.org/t/just-mappers-upgrading-from-old-rom-mapper-use/601/2 "2023-03-21T19:18:54Z")

</div>

Wow, yeah that is quite old. Based on whats happening in that blog post, it sounds like you just need data transformations and not persistence?

These tools have evolved considerably since the writing of that.

Rather than using `ActiveModel::Validations` (seeing @solnic recommend an AR lib is amusing), a far better tool today would be [dry-schema](https://dry-rb.org/gems/dry-schema/1.10/) / [dry-validation](https://dry-rb.org/gems/dry-validation/1.8/).

You could probably rewrite the transformations using [dry-transformer](https://dry-rb.org/gems/dry-transformer/0.1/) (formerly transproc).

I would be happy to go into more detail here if you give me a concrete use-case to show you.

---

<div class="post-metadata">

**Author:** ![brcarp](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/brcarp/32/294_2.png) [@brcarp](https://discourse.rom-rb.org/u/brcarp)\
**Post date:** [March 22, 2023, 2:36pm UTC](https://discourse.rom-rb.org/t/just-mappers-upgrading-from-old-rom-mapper-use/601/3 "2023-03-22T14:36:05Z")

</div>

Yeah, it’s an old use case of this for sure. It appears to be a bunch of transformers/mappers, some more basic classes with calls to `attribute` and other written like this:

```auto
class Foo < ::ROM::Mapper
  step do
    attribute("x", from: "other_x")
    attribute("y") do |y|
      # [...]
    end
  end

  step do
    # [...]
  end
end

```

Later, two or more classes will be chained together and fed to something like this:

```auto
mapper_chain.reduce(data) do |processed, mapper|
  mapper.build.call(processed)
end

```

There’s some additional work that happens where transformed data is further altered and `.call` is used again. So it could be that `dry-transformer` is right tool here. I was hoping to split the difference by first bringing the dependencies as up-to-date as possible before committing all this code to a rewrite.

---

<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:** [March 22, 2023, 6:19pm UTC](https://discourse.rom-rb.org/t/just-mappers-upgrading-from-old-rom-mapper-use/601/4 "2023-03-22T18:19:56Z")

</div>

> `attribute("x", from: "other_x")`

This looks like [copy\_keys](https://www.rubydoc.info/gems/dry-transformer/Dry/Transformer/HashTransformations#copy_keys-class_method)

```ruby
class Foo < Dry::Transformer::Pipe
  define! do
    copy_keys other_x: :x
  end
end

```

```ruby
mapper_chain.reduce(data) do |processed, mapper|
  mapper.build.call(processed)
end

```

this would end up looking more like

```ruby
mapper_chain.reduce(:>>).call(data)

```

assuming `mapper_chain` is a list of transformer instances.

The modern convention is to use [dry-container](https://dry-rb.org/gems/dry-container/0.7/) to instantiate them instead of calling `build`

---

<div class="post-metadata">

**Author:** ![brcarp](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/brcarp/32/294_2.png) [@brcarp](https://discourse.rom-rb.org/u/brcarp)\
**Post date:** [March 22, 2023, 8:43pm UTC](https://discourse.rom-rb.org/t/just-mappers-upgrading-from-old-rom-mapper-use/601/5 "2023-03-22T20:43:40Z")

</div>

Thanks for the tip! I’m definitely going to have to dig into the documentation a bit and see if I can translate all of it to more modern conventions.

---

<div class="post-metadata">

**Author:** ![pboling](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/pboling/32/299_2.png) [@pboling](https://discourse.rom-rb.org/u/pboling)\
**Post date:** [June 22, 2023, 9:37am UTC](https://discourse.rom-rb.org/t/just-mappers-upgrading-from-old-rom-mapper-use/601/6 "2023-06-22T09:37:12Z")

</div>

@brcarp Did you end up with a happy solution? Can you give any hints as to what worked? I expect I’ll be needing to implement low level transformations as well.

---

<div class="post-metadata">

**Author:** ![brcarp](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/brcarp/32/294_2.png) [@brcarp](https://discourse.rom-rb.org/u/brcarp)\
**Post date:** [June 23, 2023, 6:00pm UTC](https://discourse.rom-rb.org/t/just-mappers-upgrading-from-old-rom-mapper-use/601/7 "2023-06-23T18:00:38Z")

</div>

> [@pboling](#):
>
> Did you end up with a happy solution? Can you give any hints as to what worked? I expect I’ll be needing to implement low level transformations as well.

It’s in our backlog, but hasn’t been addressed yet. So no solutions to share at this point, but I can update later if there are any developments.
