Skip to content

Commit

Permalink
Merge pull request #1854 from Shopify/cbothner/add-reset_association
Browse files Browse the repository at this point in the history
Add `reset_association` method signature for singular AR associations
  • Loading branch information
cbothner committed Apr 16, 2024
2 parents cd0be5b + 2e4b4a3 commit f29ea5d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/tapioca/dsl/compilers/active_record_associations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ module Compilers
#
# sig { returns(T.nilable(::Category)) }
# def reload_category; end
#
# sig { void }
# def reset_author; end
#
# sig { void }
# def reset_category; end
# end
# end
# ~~~
Expand Down Expand Up @@ -196,6 +202,10 @@ def populate_single_assoc_getter_setter(klass, association_name, reflection)
"reload_#{association_name}",
return_type: association_type,
)
klass.create_method(
"reset_#{association_name}",
return_type: "void",
)
unless reflection.polymorphic?
klass.create_method(
"build_#{association_name}",
Expand Down
6 changes: 6 additions & 0 deletions manual/compiler_activerecordassociations.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ class Post

sig { returns(T.nilable(::Category)) }
def reload_category; end

sig { void }
def reset_author; end

sig { void }
def reset_category; end
end
end
~~~
48 changes: 48 additions & 0 deletions spec/tapioca/dsl/compilers/active_record_associations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ def reload_author; end
sig { returns(T.nilable(::Category)) }
def reload_category; end
sig { void }
def reset_author; end
sig { void }
def reset_category; end
end
end
RBI
Expand Down Expand Up @@ -195,6 +201,9 @@ def category_attributes=(attributes); end
sig { returns(T.untyped) }
def reload_category; end
sig { void }
def reset_category; end
end
end
RBI
Expand Down Expand Up @@ -294,6 +303,9 @@ def create_author!(*args, &blk); end
sig { returns(T.nilable(::User)) }
def reload_author; end
sig { void }
def reset_author; end
end
end
RBI
Expand Down Expand Up @@ -557,6 +569,9 @@ def create_author!(*args, &blk); end
sig { returns(T.nilable(::Blog::Author)) }
def reload_author; end
sig { void }
def reset_author; end
end
end
RBI
Expand Down Expand Up @@ -627,6 +642,9 @@ def post=(value); end
sig { returns(T.nilable(::Blog::Core::Post)) }
def reload_post; end
sig { void }
def reset_post; end
end
end
RBI
Expand Down Expand Up @@ -745,6 +763,9 @@ def create_shop!(*args, &blk); end
sig { returns(T.nilable(::Shop)) }
def reload_shop; end
sig { void }
def reset_shop; end
sig { returns(T.nilable(::Shop)) }
def shop; end
Expand Down Expand Up @@ -858,6 +879,12 @@ def reload_author; end
sig { returns(T.nilable(::Category)) }
def reload_category; end
sig { void }
def reset_author; end
sig { void }
def reset_category; end
end
end
RBI
Expand Down Expand Up @@ -897,6 +924,9 @@ def category_attributes=(attributes); end
sig { returns(T.untyped) }
def reload_category; end
sig { void }
def reset_category; end
end
end
RBI
Expand Down Expand Up @@ -996,6 +1026,9 @@ def create_author!(*args, &blk); end
sig { returns(T.nilable(::User)) }
def reload_author; end
sig { void }
def reset_author; end
end
end
RBI
Expand Down Expand Up @@ -1259,6 +1292,9 @@ def create_author!(*args, &blk); end
sig { returns(T.nilable(::Blog::Author)) }
def reload_author; end
sig { void }
def reset_author; end
end
end
RBI
Expand Down Expand Up @@ -1329,6 +1365,9 @@ def post=(value); end
sig { returns(T.nilable(::Blog::Core::Post)) }
def reload_post; end
sig { void }
def reset_post; end
end
end
RBI
Expand Down Expand Up @@ -1447,6 +1486,9 @@ def create_shop!(*args, &blk); end
sig { returns(T.nilable(::Shop)) }
def reload_shop; end
sig { void }
def reset_shop; end
sig { returns(T.nilable(::Shop)) }
def shop; end
Expand Down Expand Up @@ -1524,6 +1566,12 @@ def reload_photo_attachment; end
sig { returns(T.untyped) }
def reload_photo_blob; end
sig { void }
def reset_photo_attachment; end
sig { void }
def reset_photo_blob; end
end
end
RBI
Expand Down

0 comments on commit f29ea5d

Please sign in to comment.