# Rom-sql relation's \`fetch\` doesn't seem to support mapping

**URL:** <https://discourse.rom-rb.org/t/rom-sql-relations-fetch-doesnt-seem-to-support-mapping/239>\
**Category:** Issues\
**Created:** [April 13, 2018, 7:13am UTC](https://discourse.rom-rb.org/t/rom-sql-relations-fetch-doesnt-seem-to-support-mapping/239 "2018-04-13T07:13:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![joelvh](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/joelvh/32/139_2.png) [@joelvh](https://discourse.rom-rb.org/u/joelvh)\
**Post date:** [April 13, 2018, 7:13am UTC](https://discourse.rom-rb.org/t/rom-sql-relations-fetch-doesnt-seem-to-support-mapping/239/1 "2018-04-13T07:13:37Z")

</div>

I’ve created a finder method on my repository. When calling `fetch` on the association while specifying `map_with`, the resulting entity is a struct instead of the mapped class.

```ruby
def by_id(event_id)
  events.map_with(:mapped_event_mapper).fetch(event_id)
end

# Example:

repo.by_id(123)
# => #<ROM::Struct::Event id="...">

```

However, when I use the same rom-sql code that’s used internally by `fetch` (Discourse won’t let me link to GitHub), it works:

```ruby
def by_id(event_id)
  events.map_with(:mapped_event_mapper).by_pk(event_id).one!
end

# Example:

repo.by_id(123)
# => #<MappedEvent id="...">

```

`fetch` calls `by_pk(event_id).one!` internally, so it’s odd this behavior differs.

---

<div class="post-metadata">

**Author:** ![solnic](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/solnic/32/279_2.png) [@solnic](https://discourse.rom-rb.org/u/solnic)\
**Post date:** [April 17, 2018, 11:52am UTC](https://discourse.rom-rb.org/t/rom-sql-relations-fetch-doesnt-seem-to-support-mapping/239/2 "2018-04-17T11:52:31Z")

</div>

Are you using latest rom and latest rom-mapper? I fixed a couple of things in `#map_with` so maybe that’s it.

---

<div class="post-metadata">

**Author:** ![joelvh](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/joelvh/32/139_2.png) [@joelvh](https://discourse.rom-rb.org/u/joelvh)\
**Post date:** [April 25, 2018, 7:14pm UTC](https://discourse.rom-rb.org/t/rom-sql-relations-fetch-doesnt-seem-to-support-mapping/239/3 "2018-04-25T19:14:20Z")

</div>

Hi @solnic, yes, been using the latest. Ended up not using `fetch`.
