rom icon indicating copy to clipboard operation
rom copied to clipboard

Unable to modify the node of a combined assc. when a child of that assc. is combined.

Open dhnaranjo opened this issue 2 years ago • 0 comments

Describe the bug

When using nested combine you are unable to modify the node of the first level of nesting. This ones is best explained by the script, but there's a fair amount of setup. The juicy part:

arel.combine(bbb: :ccc).node(:bbb) { _1.select(:id) }
# => wrong argument type Symbol (expected Array)

To Reproduce

require "rom"
require "rom-sql"
require "dry-types"
require "sqlite3"

rom = ROM.container(:sql, 'sqlite::memory') do |config|
  config.default.create_table(:cccs) do
    primary_key :id
  end
  config.default.create_table(:bbbs) do
    primary_key :id
    Integer :ccc_id
  end
  config.default.create_table(:aaas) do
    primary_key :id
    Integer :bbb_id
  end
  config.relation(:cccs) do
    schema do
      attribute :id, Dry::Types["integer"]
      primary_key :id
    end
  end
  config.relation(:bbbs) do
    schema do
      attribute :id, Dry::Types["integer"]
      primary_key :id
      attribute :ccc_id, Dry::Types["integer"]

      associations do
        belongs_to :ccc
      end
    end
  end
  config.relation(:aaas) do
    schema do
      attribute :id, Dry::Types["integer"]
      primary_key :id
      attribute :bbb_id, Dry::Types["integer"]

      associations do
        belongs_to :bbb
      end
    end
  end
end

arel = rom.relations[:aaas]
brel = rom.relations[:bbbs]
crel = rom.relations[:cccs]

brel.changeset(:create, id: 1).commit
crel.changeset(:create, id: 1).commit
arel.changeset(:create, bbb_id: 1, ccc_id: 1).commit

arel.combine(bbb: :ccc).node(:bbb) { _1.select(:id) }
# => wrong argument type Symbol (expected Array)

Expected behavior

I can work with the first level node.

My environment

  • Affects my production application: no
  • Ruby version: 3.1.1
  • OS: M1 Mac

dhnaranjo avatar Mar 28 '22 23:03 dhnaranjo