rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.07k stars 161 forks source link

Error when a relation with the name `options` exists. #675

Open dhnaranjo opened 2 years ago

dhnaranjo commented 2 years ago

Describe the bug

When a relation with the name options exists the following error is raised when you create an instance of it:

rom-core-5.2.6/lib/rom/schema.rb:232:in `[]': :struct_namespace attribute doesn't exist in options schema (KeyError)

This happens because ROM::Initializer::InstanceMethods#options is called at either ROM::Relation#struct_namespace or ROM::Relation#meta_ast.

To Reproduce

require "rom"
require "dry-types"

rom = ROM.container(:memory, 'memory://test') do |config|
  config.relation(:options) do
    schema do
      attribute :whatever, Dry::Types["string"]
    end
  end
end

options = rom.relations[:options]
options.changeset(:create, whatever: "who cares").commit

Expected behavior

A relation named options doesn't poop my app

My environment

dhnaranjo commented 2 years ago

Cool thing about being pre-launch is I just went and changed the table name, so I'm not urgently awaiting a fix or nothing.

solnic commented 2 years ago

Thanks for reporting this. It's been on my radar as it's a general issue of having reserved names that cannot be used as relation names. This will be properly addressed in 6.0.