This repository has been archived by the owner on Jul 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
Ability to call a model's class methods on the model's CollectionProxy #104
Labels
bug
Something isn't working
Comments
Reproduced by sample appHere is a sample app that reproduces this issue with the latest versions of all gems. (currently https://github.com/jaredbeck/srb_ar_proxy HighlightsModel# 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
|
Thanks for flagging. I think it’ll be a difficult problem to solve. Rails
dynamically routes missing methods from CollectionProxy to a Rails Model
(another class). All user-defined class methods in a rails model is
available in CollectionProxy. We can detect the method but it’ll likely be
difficult to generate the method _and_ the signature correctly. I don’t
know if sorbet provide any way to inflect signature for a method.
…On Thu, Aug 15, 2019 at 12:16 PM Jared Beck ***@***.***> wrote:
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: trueclass Task < ApplicationRecord
def self.outstanding
where 'due < ?', Time.current
endend
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
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#104?email_source=notifications&email_token=AAFH4AK7RPHGAGZZTKLHMNTQEWTRNA5CNFSM4IIHAS52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4MXODI#issuecomment-521762573>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAFH4AP7XZYMWSENGSPTUUTQEWTRNANCNFSM4IIHAS5Q>
.
|
Jared: For the example you gave, you can turn it into a scope easily.
Scopes are detected automatically by Sorbet-rails.
…On Thu, Aug 15, 2019 at 12:31 PM Al Snow ***@***.***> wrote:
How does bin/outstnding.rb normally work (without sorbet)?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#104?email_source=notifications&email_token=AAFH4ANAHK3L4JW64LYDI7LQEWVJXA5CNFSM4IIHAS52YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD4MYUCI#issuecomment-521767433>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAFH4ANFYORUFNRTDZDSOBDQEWVJXANCNFSM4IIHAS5Q>
.
|
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
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?
#.
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:
The text was updated successfully, but these errors were encountered: