Sorbet-rails 不为 rails has_many、belongs_to 等生成 RBI
Sorbet-rails not generating RBI's for rails has_many, belongs_to, etc
也许我在初始化过程中遗漏了一些东西,但是 sorbet-rails
似乎无法为某些默认 rails 方法(例如 has_many
、belongs_to
、validates
,等等)。可以看到生成了对应的generated association,但是收到类型投诉主要方法不存在
例如像这样的 class:
class Role < ApplicationRecord
has_and_belongs_to_many :users, :join_table => :users_roles
我可以在 role.rbi
中看到自动生成的印记
sig { returns(::User::ActiveRecord_Associations_CollectionProxy) }
def users; end
然而,这是我在检查类型时遇到的错误:
Method has_and_belongs_to_many does not exist on T.class_of(Role) https://srb.help/7003
3 | has_and_belongs_to_many :users, :join_table => :users_roles
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
此错误是 sorbet
不知道 has_and_belongs_to_many
方法存在的错误。通常这是由 sorbet
本身提供的。我可以看到此方法的签名是在 sorbet-typed 的 activerecord.rbi 中定义的。在你的回购协议中,它应该在这个路径下:
sorbet/rbi/sorbet-typed/lib/activerecord/all/activerecord.rbi
你能检查一下你的仓库中是否存在该文件吗?如果没有,您可以尝试 运行 srb rbi sorbet-typed
(在 rbi files doc 之后)
Method has_and_belongs_to_many does not exist on T.class_of(Role) https://srb.help/7003
3 | has_and_belongs_to_many :users, :join_table => :users_roles
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
也许我在初始化过程中遗漏了一些东西,但是 sorbet-rails
似乎无法为某些默认 rails 方法(例如 has_many
、belongs_to
、validates
,等等)。可以看到生成了对应的generated association,但是收到类型投诉主要方法不存在
例如像这样的 class:
class Role < ApplicationRecord
has_and_belongs_to_many :users, :join_table => :users_roles
我可以在 role.rbi
中看到自动生成的印记 sig { returns(::User::ActiveRecord_Associations_CollectionProxy) }
def users; end
然而,这是我在检查类型时遇到的错误:
Method has_and_belongs_to_many does not exist on T.class_of(Role) https://srb.help/7003
3 | has_and_belongs_to_many :users, :join_table => :users_roles
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
此错误是 sorbet
不知道 has_and_belongs_to_many
方法存在的错误。通常这是由 sorbet
本身提供的。我可以看到此方法的签名是在 sorbet-typed 的 activerecord.rbi 中定义的。在你的回购协议中,它应该在这个路径下:
sorbet/rbi/sorbet-typed/lib/activerecord/all/activerecord.rbi
你能检查一下你的仓库中是否存在该文件吗?如果没有,您可以尝试 运行 srb rbi sorbet-typed
(在 rbi files doc 之后)
Method has_and_belongs_to_many does not exist on T.class_of(Role) https://srb.help/7003
3 | has_and_belongs_to_many :users, :join_table => :users_roles
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^