chanzuckerberg / sorbet-rails

A set of tools to make the Sorbet typechecker work with Ruby on Rails seamlessly.
MIT License
638 stars 84 forks source link

Has_many with scope on association #425

Closed akefeli closed 3 years ago

akefeli commented 3 years ago

I have a has_many association with a scope defined on the associated class. But srb is expecting method completed to be defined in Person class. Is there a workaround for this?

Steps to reproduce:

class Person
  has_many :jobs, -> { completed }
end

class Job
  scope :completed, -> { where... }
end

Method completed does not exist on T.class_of(Person) https://srb.help/7003

Expected behavior: It should not complain about method being missing

Versions:

DanielGilchrist commented 3 years ago

To get around this you can explicitly call the scope from the model class like so:

class Person < ApplicationRecord
  has_many :jobs, -> { Job.completed }, class_name: "Job"
end

class Job < ApplicationRecord
  scope :completed, -> { where... }
end
akefeli commented 3 years ago

Ty! @DanielGilchrist