active-hash / active-hash/active_hash
where(undefined_key: nil) returns relation including all records
Open
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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