Using `type` in `where` block raise `ArgumentError`

Open
#433 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
ruby, sql, sqlite
Domain
databases

Research direction

Start by running the inline Ruby reproduction and tracing the users.where block, especially attribute lookup for the column named type. Done means the block treats type as the database column and no longer raises ArgumentError; rerun the supplied script to verify the result.

Written by the indexing model from the issue text.

Description

bug help wanted

Describe the bug

Using where { type.is(...) } raises ArgumentError: wrong number of arguments (given 0, expected 1).

To Reproduce

Run script below:

require 'bundler/inline'

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

config = ROM::Configuration.new(:sql, 'sqlite::memory')

config.gateways[:default].create_table(:users) do
  primary_key :id
  column :name, String
  column :type, String
end

class Users < ROM::Relation[:sql]
  schema do
    attribute :id, Types::Serial
    attribute :name, Types::String
    attribute :type, Types::Strict::String.enum('User', 'Admin')
  end
end

config.register_relation(Users)

container = ROM.container(config)

users = container.relations[:users]

# ArgumentError: wrong number of arguments (given 0, expected 1)
p users.where { name.is('Thomas') & type.is('Manager') }.to_a

Expected behavior

It does not raise an error but considers type as a database column.

My environment

  • Ruby: 3.2.2
  • rom-sql (3.6.4)
Dominant language
Ruby
Stars
220
Forks
97
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from rom-rb/rom-sql

All issues in rom-rb/rom-sql

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.