Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

find on has_many proxy will throw error if the relation doesn't include act_as_hashids #27

Open
noxasch opened this issue Feb 21, 2024 · 0 comments

Comments

@noxasch
Copy link

noxasch commented Feb 21, 2024

Description:

Given class as below

Class Base < ActiveRecord::Base
    self.abstract_class = true
    acts_as_hashids length: 4
  end

  class CoreFoo < Base
    has_many :core_bars
  end

  class CoreBar < Base
    belongs_to :core_foo
  end

In spec this will throw an error

# in spec - this will throw an error
let!(:foo1) { CoreFoo.create }

let(:bar3) { CoreBar.create core_foo: foo1 }
let(:bar4) { CoreBar.create core_foo: foo1 }

before do
    bar3
    bar4
end

context 'with normal id' do
   it 'should behave like normal AR' do
       expect(foo1.core_bars.find(bar3.id)).to eq bar3
   end
end

Error

NameError:
       undefined local variable or method `hashids' for #<ActiveRecord::Associations::CollectionProxy []>

Expected Output:

When using integer id or the real id, find should run without first try to encode to hashid and return the record

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant