@solnic I’ve got an example of a commit where I’m replacing a SQL join with ROM combine. There’s the “StreamEntries” which reference an “Event” ID. I want to get a list of Event entities, but they need to be ordered based on “position” in the StreamEntry entity. I’ve been attempting to not intermingle relations, but it’s proven challenging, particularly when combined with mapping.
This commit shows the change from SQL joins to ROM combine: https://github.com/joelvh/rails_event_store/commit/5a9809cdee2f34f12294658faf6a10596ee977f7
I tried using your node mapping suggestion, but we’re mapping to a custom class and something was causing an error where the mapper or combine was trying to access attributes of the mapped class via
event[...]. I was able to avoid mapping before combining by using the mapper outside the relation work.
- How can I call the mapper by it’s registered name when I have an array instead of a relation?
- Can a nested entity be mapped to a custom class? (I assume it has to be a Hash-like object because you store the combine key on the nested object)
- I’d also love to not have to loop over the result by calling
map to grab the nested “event” object, but imagine that’s probably the most practical way.
The only reason this relation work is inverted is because the ordering of the results matters, but the ordering is not on the entity that I want to return from the relation/repository.
Any suggestions on the approaches taken in the example? (This is the project I’m learning ROM with)
P.S. The tests pass, just want to see how you would do this differently.