Skip to content

ActiveHash scope affecting self #257

@mogya

Description

@mogya

Define scope on ActiveHash class and calling it, seems polluting original object.

reproduce

class Country < ActiveHash::Base
  self.data = [
    {:id => 1, :name => "US"},
    {:id => 2, :name => "Japan"}
  ]
  scope :east_asia, -> do
    where(name: "Japan")
  end
end

irb(main):054:0> c = Country.all
=> 
#<ActiveHash::Relation:...
irb(main):055:0> c.count
=> 2
irb(main):056:0> c.east_asia
=> 
#<ActiveHash::Relation:...
irb(main):057:0> c.count
=> 1

expected behavior

c.count should returns 2 because ActiveRecord scope returns new relation and do not affect to self.

environment

irb(main):058:0> ActiveHash::gem::VERSION
=> "3.1.1"
irb(main):063:0> Rails::VERSION::STRING
=> "7.0.3.1"

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