Skip to content

Commit

Permalink
Merge pull request #1823 from bdewater/ar-relations-extract-associated
Browse files Browse the repository at this point in the history
Fix return type of ActiveRecord::QueryMethods#extract_associated
  • Loading branch information
KaanOzkan committed Mar 25, 2024
2 parents e3e5e6a + f4104b6 commit 265bea2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
30 changes: 23 additions & 7 deletions lib/tapioca/dsl/compilers/active_record_relations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,29 @@ def create_relation_methods
)

QUERY_METHODS.each do |method_name|
create_relation_method(
method_name,
parameters: [
create_rest_param("args", type: "T.untyped"),
create_block_param("blk", type: "T.untyped"),
],
)
case method_name
when :extract_associated
parameters = [create_param("association", type: "Symbol")]
return_type = "T::Array[T.untyped]"
relation_methods_module.create_method(
method_name.to_s,
parameters: parameters,
return_type: return_type,
)
association_relation_methods_module.create_method(
method_name.to_s,
parameters: parameters,
return_type: return_type,
)
else
create_relation_method(
method_name,
parameters: [
create_rest_param("args", type: "T.untyped"),
create_block_param("blk", type: "T.untyped"),
],
)
end
end
end

Expand Down
8 changes: 4 additions & 4 deletions spec/tapioca/dsl/compilers/active_record_relations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ def excluding(*args, &blk); end
sig { params(args: T.untyped, blk: T.untyped).returns(PrivateAssociationRelation) }
def extending(*args, &blk); end
sig { params(args: T.untyped, blk: T.untyped).returns(PrivateAssociationRelation) }
def extract_associated(*args, &blk); end
sig { params(association: Symbol).returns(T::Array[T.untyped]) }
def extract_associated(association); end
sig { params(args: T.untyped, blk: T.untyped).returns(PrivateAssociationRelation) }
def from(*args, &blk); end
Expand Down Expand Up @@ -453,8 +453,8 @@ def excluding(*args, &blk); end
sig { params(args: T.untyped, blk: T.untyped).returns(PrivateRelation) }
def extending(*args, &blk); end
sig { params(args: T.untyped, blk: T.untyped).returns(PrivateRelation) }
def extract_associated(*args, &blk); end
sig { params(association: Symbol).returns(T::Array[T.untyped]) }
def extract_associated(association); end
sig { params(args: T.untyped, blk: T.untyped).returns(PrivateRelation) }
def from(*args, &blk); end
Expand Down

0 comments on commit 265bea2

Please sign in to comment.