简体   繁体   English

Sorbet-rails 不为 rails has_many、belongs_to 等生成 RBI

[英]Sorbet-rails not generating RBI's for rails has_many, belongs_to, etc

Maybe there's something in the initialization process that I missed, but sorbet-rails seems to having trouble generating methods for some of the default rails methods (eg has_many , belongs_to , validates , etc.).也许我错过了初始化过程中的某些内容,但是sorbet-rails似乎无法为某些默认的 rails 方法(例如has_manybelongs_tovalidates等)生成方法。 I can see that the corresponding generated association is generated, but I get type complaints that the main methods do not exist.我可以看到生成了相应的生成关联,但是我收到类型抱怨主要方法不存在。

eg a class like this:例如像这样的 class :

class Role < ApplicationRecord
  has_and_belongs_to_many :users, :join_table => :users_roles

I can see the auto generated sigil in role.rbi我可以在 role.rbi 中看到自动生成的印记

  sig { returns(::User::ActiveRecord_Associations_CollectionProxy) }
  def users; end

However this is the error I get when checking types:但是,这是我在检查类型时遇到的错误:

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
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This error is an error with sorbet not knowing that has_and_belongs_to_many method exists.此错误是sorbet不知道has_and_belongs_to_many方法存在的错误。 Usually this is provided by sorbet itself.通常这是由sorbet本身提供的。 I can see the signature of this method is defined in sorbet-typed's activerecord.rbi .我可以看到这种方法的签名是在 sorbet-typed 的activerecord.rbi中定义的。 In your repo it should be under this path:在您的仓库中,它应该位于此路径下:

sorbet/rbi/sorbet-typed/lib/activerecord/all/activerecord.rbi

Can you check if the file exists in your repo?您可以检查该文件是否存在于您的存储库中吗? if not, you could try running srb rbi sorbet-typed (following the rbi files doc )如果没有,您可以尝试运行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
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM