Chaining combines

Given I have 2 relations:

class ShiftPositions < ROM::Relation[:sql]
  schema(:shift_positions, infer: true) do
    associations do
      belongs_to :position
      belongs_to :pay_type
    end
  end

  def with_position_and_pay_type
    combine(:position, :pay_type)
  end
end
class Shifts < ROM::Relation[:sql]
  schema(:shifts, infer: true) do
    associations do
      has_many :shift_positions
    end
  end

  def with_shift_positions
    combine(shift_positions: %i[position pay_type])
    # TODO: how can I use the `with_position_and_pay_type` method here?
  end
end

How can I use with_position_and_pay_type inside with_shift_positions?

I suggest you would move the question outside the code :slight_smile:
At first reading I wasn’t able to spot it!

Have you tried using it directly, ie. combine(...).with_position_and_pay_type?

I did,

undefined methodwith_position_and_pay_type’ for #ROM::Relation::Combined:0x000055ad1502c138`

Ah I got it, need to use combine#node

        combine(:shift_positions)
          .node(:shift_positions) do |shift_positions_rel|
          shift_positions_rel.with_position_and_pay_type
        end
1 Like