-
Notifications
You must be signed in to change notification settings - Fork 125
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
ActiveRecordAssociations compiler crashes on association defined with ActiveHash #1286
Comments
I'm not familiar with The compiler requires a valid association and utilizes the database state to generate RBIs. I don't know the internals of Do you have a model called If |
Thanks for your help.
Yes. I have a model like below. # Example app/models/prefecture.rb
class Prefecture < ActiveHash::Base
self.data = [
{:id => 1, :name => "Foo"},
{:id => 2, :name => "Bar"}
]
end I might be catching on to the cause. > ActiveHash::Base.ancestors
=>
[ActiveHash::Base,
ActiveModel::Conversion,
ActiveSupport::Dependencies::RequireDependency,
ActiveSupport::ToJsonWithActiveSupportEncoder,
Object,
PP::ObjectMixin,
ActiveSupport::Tryable,
JSON::Ext::Generator::GeneratorMethods::Object,
Kernel,
BasicObject]
I'm still not sure about the approach though, do you mean I need to implement another compiler? Or, can any existing compiler do this? In the meantime, I'm going to exclude the compiler in the way you taught me. 👍 |
Thanks for the context. You'd have to write a custom compiler for ActiveHash. There's detailed documentation here. In the end it'd look similar to the assocations compiler. In
Once you have that information you can generate modules and methods for your RBI files using the same API as the other compilers ( |
Thanks for the detailed advice. I'll try to write a custom compiler referring to your guide. |
I found that active_hash repo has an issue related to this problem: active-hash/active_hash#267. According to that, this problem could happen with only Rails 7.0 or above. And I confirmed ActiveRecordAssociations compiler works even with active_hash once the issue gets resolved. So I'm closing this issue. Thanks for your kind help! |
I'm quite new to tapioca, so please tell me if it's not the right place to report.
Problem
ActiveRecordAssociations compiler does not work with active_hash.
Reproduce
I'm using active_hash with ActiveRecord like this.
I ran the command below then got the error.
Actual Behavior
Expected Behavior
No errors and tapioca outputs RBI (regardless of whether it includes the association defined with active_hash).
Environment
tapioca config is empty.
The text was updated successfully, but these errors were encountered: