-
Notifications
You must be signed in to change notification settings - Fork 134
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Association DSL generates generic CollectionProxy sig #179
Comments
Hello again! Indeed, this aspect of Tapioca is, unfortunately not ready for prime-time yet! 😞 The initial implementation of our AR generators reference an internal hack that redefines We are trying to implement a generator for AR relations that will do this properly, but, that is not ready yet. In the meanwhile, feel free to dump the following in an RBI file and that should get you going: class ActiveRecord::Associations::CollectionProxy < ::ActiveRecord::Relation
extend(T::Generic)
Elem = type_member
sig { params(block: T.nilable(T.proc.params(arg: Elem).void)).returns(T::Enumerator[Elem]) }
def each(&block); end
sig do
returns(T.untyped)
end
def target; end
sig { void }
def load_target; end
sig { void }
def reload; end
sig { void }
def reset; end
sig { void }
def reset_scope; end
sig { returns(T::Boolean) }
def loaded?; end
sig { params(args: T.untyped).returns(Elem) }
def find(*args); end
def last(limit = nil); end
def take(limit = nil); end
sig do
params(attributes: ::Hash, block: T.nilable(T.proc.returns(T.untyped))).returns(Elem)
end
def build(attributes = {}, &block); end
sig do
params(attributes: ::Hash, block: T.nilable(T.proc.returns(T.untyped))).returns(Elem)
end
def create(attributes = {}, &block); end
sig do
params(attributes: ::Hash, block: T.nilable(T.proc.returns(T.untyped))).returns(Elem)
end
def create!(attributes = {}, &block); end
sig { params(records: T.any(Elem, T::Array[Elem], T::Array[ActiveRecord::Associations::CollectionProxy[Elem]])).void }
def concat(*records); end
sig { params(other_array: T.any(T::Array[Elem], T.self_type)).void }
def replace(other_array); end
sig { params(dependent: ::Symbol).void }
def delete_all(dependent = nil); end
sig { void }
def destroy_all; end
sig { params(records: T.any(Elem, T::Array[Elem])).void }
def delete(*records); end
sig { params(records: T.any(Elem, T::Array[Elem])).void }
def destroy(*records); end
def calculate(operation, column_name); end
def pluck(*column_names); end
sig { returns(::Integer) }
def size; end
sig { returns(T::Boolean) }
def empty?; end
sig { params(record: Elem).returns(T::Boolean) }
def include?(record); end
def proxy_association; end
def scope; end
sig { params(other: T.any(T.self_type, T::Array[Elem])).returns(T::Boolean) }
def ==(other); end
sig { params(records: T.any(Elem, T::Array[Elem], T::Array[ActiveRecord::Associations::CollectionProxy[Elem]])).void }
def <<(*records); end
sig { params(args: Elem).void }
def prepend(*args); end
sig { void }
def clear; end
sig { params(fields: T.any(Symbol, String)).returns(ActiveRecord::Associations::CollectionProxy[Elem]) }
def select(*fields); end
end |
Thank you @paracycle for the quick response! I'll try that out and see how it goes. 😁 |
Please let me know how you get on so that I can close this issue or provide more help to get you up and running. |
@paracycle Yes, this worked great. Thank you! Please feel free to close. |
If I have this model
When I run
tapioca dsl
, theuser.rbi
that is generated contains this:When I run
srb tc
, Sorbet complains of a type errorI also checked out the
sorbet/rbi/gems/activerecord@6.0.3.4.rbi
file that was generated when I rantapioca sync
, and in thereCollectionProxy
is only defined likeSo I'm assuming the problem is that the type definition for
CollectionProxy
is not generic, but the generateduser.rbi
is assuming it is and trying to pass a type parameter.This was starting from a code base with neither Sorbet nor Tapioca, running these commands:
Did I miss some other step?
My version info:
The text was updated successfully, but these errors were encountered: