Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken example code, unexpected auto_struct behavior #685

Open
pboling opened this issue Jun 21, 2023 · 0 comments
Open

Broken example code, unexpected auto_struct behavior #685

pboling opened this issue Jun 21, 2023 · 0 comments

Comments

@pboling
Copy link

pboling commented Jun 21, 2023

Describe the bug

I made a script of the example code, and it seems that the example code for the auto-generated structs no longer reflects reality, and as a result I am very confused about how to setup my custom name-spaced structs, when not even the auto-generated ones work as expected.

The example code I mostly copied is here: https://api.rom-rb.org/rom/ROM/Struct
Note that as written the example code doesn't work at all, as it was missing the conf.relation(:users), so I added that. Even with that, the example code still doesn't work at all, and raises the error:
undefined method 'schema' for ROM::OpenStruct:Class (NoMethodError)

To Reproduce

require 'bundler/inline'

gemfile do
  source 'https://rubygems.org'
  gem 'rom'
  gem 'rom-sql'
  gem 'sqlite3'
end

rom = ROM.container(:sql, 'sqlite::memory') do |conf|
  conf.default.create_table(:users) do
    primary_key :id
    column :name, String
  end

  conf.relation(:users) do
  end
end

class UserRepo < ROM::Repository[:users]
end

user_repo = UserRepo.new(rom)

# get auto-generated User struct
model = user_repo.users.mapper.model

puts "model: #{model}"
# EXPECTED
# model: ROM::Struct::User
#
# ACTUAL
# model: ROM::OpenStruct

puts model.schema.key(:id)
# EXPECTED:
# #<Dry::Types[id: Nominal<Integer meta={primary_key: true, source: :users}>]>
#
# ACTUAL:
# undefined method `schema' for ROM::OpenStruct:Class (NoMethodError)

My environment

  • Affects my production application: NOT YET (Implementing ROM as part of a new service)
  • Ruby version: 2.7.8 through 3.2.2
  • OS: macOS Ventura 13.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant