In the documentation (ROM - Mappers ) you can use the >> operator to pass data to a custom mapper.
If I have defined a mapper class inheriting from ROM::Transformer, what would the syntax be to pass data to it via >> (or other method)?
I’m aware of Relation#map_with
but I need to pass a cached value into the mapper. How can I do this?
Many thanks!!
solnic
February 14, 2023, 7:17am
2
Could you show an example of what you’re trying to achieve? I’m not sure what you’re after exactly.
Given that I have a mapper class defined MyMapper:
result = my_relation.by_pk(id)
…some other code
send result through mapper here without hitting the db…
mapped_results = results >> MyMapper.new ??
Is this possible and what is the correct syntax?
solnic
February 16, 2023, 9:36am
4
Ohh, it’s just a function. So my_mapper.call(results)
Thank you! That seems obvious now given " A mapper can be any object which responds to #call
, which accepts a relation and return an array with results back".
Sorry to take your time for this.
solnic
February 17, 2023, 7:47am
7
No worries I hope it does the trick for you.