Skip to content

where(undefined_key: nil) returns relation including all records #190

@unhappychoice

Description

@unhappychoice

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions