# Chaining combines

**URL:** <https://discourse.rom-rb.org/t/chaining-combines/260>\
**Category:** Issues\
**Created:** [June 28, 2018, 6:35pm UTC](https://discourse.rom-rb.org/t/chaining-combines/260 "2018-06-28T18:35:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![calin](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/calin/32/103_2.png) [@calin](https://discourse.rom-rb.org/u/calin)\
**Post date:** [June 28, 2018, 6:35pm UTC](https://discourse.rom-rb.org/t/chaining-combines/260/1 "2018-06-28T18:35:33Z")

</div>

Given I have 2 relations:

```auto
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

```

```auto
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`?

---

<div class="post-metadata">

**Author:** ![apohllo](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/apohllo/32/86_2.png) [@apohllo](https://discourse.rom-rb.org/u/apohllo)\
**Post date:** [June 28, 2018, 7:29pm UTC](https://discourse.rom-rb.org/t/chaining-combines/260/2 "2018-06-28T19:29:26Z")

</div>

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

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

---

<div class="post-metadata">

**Author:** ![calin](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/calin/32/103_2.png) [@calin](https://discourse.rom-rb.org/u/calin)\
**Post date:** [June 29, 2018, 3:58am UTC](https://discourse.rom-rb.org/t/chaining-combines/260/3 "2018-06-29T03:58:32Z")

</div>

I did,

`undefined method`with\_position\_and\_pay\_type’ for #ROM::Relation::Combined:0x000055ad1502c138`

---

<div class="post-metadata">

**Author:** ![calin](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.rom-rb.org/calin/32/103_2.png) [@calin](https://discourse.rom-rb.org/u/calin)\
**Post date:** [June 29, 2018, 4:04am UTC](https://discourse.rom-rb.org/t/chaining-combines/260/4 "2018-06-29T04:04:18Z")

</div>

Ah I got it, need to use `combine#node`

```auto
        combine(:shift_positions)
          .node(:shift_positions) do |shift_positions_rel|
          shift_positions_rel.with_position_and_pay_type
        end

```
