# Relation#map\_to does nothing?

**URL:** <https://discourse.rom-rb.org/t/relation-map-to-does-nothing/618>\
**Category:** Issues\
**Created:** [July 7, 2023, 5:57pm UTC](https://discourse.rom-rb.org/t/relation-map-to-does-nothing/618 "2023-07-07T17:57:54Z")\
**Posts on this page:** 2\
**Page:** 1

<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:** [July 7, 2023, 5:57pm UTC](https://discourse.rom-rb.org/t/relation-map-to-does-nothing/618/1 "2023-07-07T17:57:54Z")

</div>

[Learning site](https://rom-rb.org/5.0/learn/core/structs/#mapping-to-custom-objects) has:

```auto
class User
  attr_reader :attributes

  def initialize(attributes)
    @attributes = attributes
  end

  def [](name)
    attributes[name]
  end
end

users.by_pk(1).map_to(User)
# => #<User:0x007fa7eabf1a50 @attributes={:id=>1, :name=>"Jane"}>

```

This is not what happens.

Using the generic User code as above, and my watches relation posted in other threads, I get this:

```auto
query_mapped = WATCH_REPO.watches.by_pk(1).map_to(User)

puts query_mapped.inspect

#<Marv::SqlRelations::Watches name=ROM::Relation::Name(watches) dataset=#<Sequel::SQLite::Dataset: "SELECT `watches`.`id`, `watches`.`watch_type`, `watches`.`created_at`, `watches`.`updated_at` FROM `watches` WHERE (`watches`.`id` = 1) ORDER BY `watches`.`id`">>

```

It doesn’t map to the User class at all. What am I missing?

---

<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:** [July 7, 2023, 6:21pm UTC](https://discourse.rom-rb.org/t/relation-map-to-does-nothing/618/2 "2023-07-07T18:21:09Z")

</div>

The documentation is incomplete. The mapping to the custom object happens when `to_a` is called.

```auto
query_mapped = WATCH_REPO.watches.by_pk(1).map_to(User).to_a

puts query_mapped.inspect

```

This will result in an array of `User` instances (length 1), similar to how it is shown in the documentation!
