active-hash / active-hash/active_hash

where(undefined_key: nil) returns relation including all records

Open
#190 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Ruby
Stars
1.4k
Forks
186
PR merge metrics
No merged PRs in 30d

Description

Description

Now, where(undefined_key: nil) returns all records.
But I think where(undefined_key: nil) should raise an error because

  • It's same as ActiveRecord behavior.
  • We cannot recognize typo and get a surprising result.
Code to reproduce
class Records < ActiveHash::Base
  self.data = [
    { id: 1, name: 'foo' },
    { id: 2, name: 'bar' },
    { id: 3, name: 'baz' }
  ]
end

pp Records.where(undefined_key: nil).to_a
# [
#    #<Records:0x00007fadaf51a5e0 @attributes={:id=>1, :name=>"foo"}>,
#    #<Records:0x00007fadaf519988 @attributes={:id=>2, :name=>"bar"}>,
#   #<Records:0x00007fadaf519348 @attributes={:id=>3, :name=>"baz"}>
# ]
Other informations
  • This will be breaking change

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start with the Records.where(undefined_key: nil) reproduction and trace how where handles hash conditions. Verify the behavior against the supplied ActiveRecord comparison, then add coverage showing that an undefined key raises an error instead of returning all records. The issue does not name a source file or test file.

Written by the indexing model from the issue text.

Assessment

Tech stack
ruby
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.