Open qsona opened 3 years ago
I wonder if this is handled by https://github.com/zilkey/active_hash/pull/158 It is an old PR and stale by now - but is this addressing the same need?
Any update?
Having same issue here, rails 7.0.8, active_hash 2.3.0...
@qsona The temporary fix works, thanks!
@kbrock the needs seems not to be the same, basically I just added class_name: '...'
to the belongs_to
call and it is sufficient to raise the exception described.
Environment
Problem
This works
But this doesn't work.
error message:
Note that this error occurs when the Bar class is first loaded, not when executing
bar.foo
.Temporal solution
It can be avoided by first calling
belongs_to
and thenextend ActiveHash::Associations::ActiveRecordExtensions
.e.g.
This solution cannot be used when you extend ApplicationRecord or ActiveRecord::Base directly (
ActiveRecord::Base.extend ActiveHash::Associations::ActiveRecordExtensions
(docs).Steps to Reproduce the Problem
rails new my_active_hash_test --minimal
active_hash
to Gemfile, and bundle installbundle exec rake db:create
bundle exec rails g model Foo
,bundle exec rails g model Bar
bundle exec rails c
and add records, thenBar#foo
can be called successfullybundle exec rails c
, and loadBar
class