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 82
Define 'new' method on model classes #174
Labels
bug
Something isn't working
Comments
Actually, since we know what parameters it takes can we use the correct method signature? class User
sig { params(attributes: T.untyped, block: T.untyped).returns(User) }
def self.new(attributes = nil, &block); end
end |
@manhhung741 IIRC, you mentioned at once point that the Sorbet team didn't want to add a special type that'd return an instance of a class (e.g. instead of |
That reminds me... Does `Model.create` work? Do we also need one for it?
…On Sat, Sep 14, 2019 at 6:06 PM Connor Shea ***@***.***> wrote:
Actually, since we know what parameters it takes can we use the correct
method signature?
class User
sig { params(attributes: T.untyped, block: T.untyped).returns(User) }
def self.new(attributes = nil, &block); endend
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#174?email_source=notifications&email_token=AAFH4AKWNEEI4GND2QTL53DQJWDDFA5CNFSM4IWYW4PKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6XHAKA#issuecomment-531525672>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAFH4AOLTATAQDXQZOXRFQLQJWDDFANCNFSM4IWYW4PA>
.
|
|
They want to add it, but they are still working on it. It’s also one of
their most requested features currently.
…On Sat, Sep 14, 2019 at 6:12 PM Connor Shea ***@***.***> wrote:
create is handled in sorbet-typed right now, but it just returns T.untyped
.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#174?email_source=notifications&email_token=AAFH4ALXV5H5BNQKJDM5OT3QJWDWDA5CNFSM4IWYW4PKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6XHBWI#issuecomment-531525849>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAFH4APRF7SUHLH5DLJSR6TQJWDWDANCNFSM4IWYW4PA>
.
|
Where should I put the |
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Describe the bug:
ActiveRecord overrides the
new
method for all Model classes, e.g.User.new
.It's defined like this in
activerecord.rbi
:And then
User
, or any other model, inherits that method.Expected behavior:
I could have an
app/controllers/users_controller.rb
file like this:The method should be generated as part of Sorbet Rails so its return type can be dynamically set:
Unfortunately it can't just be
self_type
because that doesn't return an instance of the caller :/The text was updated successfully, but these errors were encountered: