Skip to content
This repository has been archived by the owner on Jul 5, 2023. It is now read-only.

Ability to call a model's class methods on the model's CollectionProxy #104

Closed
frewsxcv opened this issue Jul 31, 2019 · 5 comments
Closed
Labels
bug Something isn't working

Comments

@frewsxcv
Copy link
Contributor

Describe the bug:

Rails has the ability to call class methods on a model's CollectionProxy. See this SO for an example:

https://stackoverflow.com/questions/22304809/rails-ability-to-call-my-class-method-on-an-array

This behavior is not currently supported in sorbet-rails

Steps to reproduce:

N/A

Expected behavior:

It should typecheck

Versions:

  • Ruby: ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin18]
  • Rails: Rails 5.2.3
  • Sorbet: Sorbet typechecker 0.4.4507 git d12b7144d2222398e0f28a772b7759fe26b2b9ba built on 2019-07-25 20:18:14 GMT with debug symbols
  • Sorbet-Rails: 0.4.0
@frewsxcv frewsxcv added the bug Something isn't working label Jul 31, 2019
@jaredbeck
Copy link
Contributor

Reproduced by sample app

Here is a sample app that reproduces this issue with the latest versions of all gems. (currently sorbet-rails 0.5.0)

https://github.com/jaredbeck/srb_ar_proxy

Highlights

Model

# typed: true
class Task < ApplicationRecord
  def self.outstanding
    where 'due < ?', Time.current
  end
end

Call Site

# typed: true

# run me with bin/rails runner bin/outstanding.rb

puts Task.all.outstanding.count

tc Output

bin/srb tc
bin/outstanding.rb:5: Method outstanding does not exist on Task::ActiveRecord_Relation https://srb.help/7003
     5 |puts Task.all.outstanding.count
             ^^^^^^^^^^^^^^^^^^^^
    sorbet/rails-rbi/models/task.rbi:128: Did you mean: Task::ModelRelationShared#extending?
     128 |  def extending(*args, &block); end
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Errors: 1

@hdoan741
Copy link
Contributor

hdoan741 commented Aug 15, 2019 via email

@hdoan741
Copy link
Contributor

hdoan741 commented Aug 15, 2019 via email

@frewsxcv frewsxcv changed the title Ability to call models class methods on a model's CollectionProxy Ability to call a model's class methods on the model's CollectionProxy Aug 17, 2019
@hdoan741
Copy link
Contributor

I'll close this for now because I don't think it's possible.

@jaredbeck
Copy link
Contributor

I'll close this for now because I don't think it's possible.

OK, thanks for looking into it.

#133 documents this as a known issue.

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants