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.
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:
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.