gem_rbs_collection icon indicating copy to clipboard operation
gem_rbs_collection copied to clipboard

Add type definitions to delete_all

Open k-in0ue opened this issue 1 year ago • 5 comments

Fix types definitions for delete_all methods. Changed the return type of delete_all methods to Integer.

k-in0ue avatar Oct 31 '24 02:10 k-in0ue

@kazuyainoue0124 Thanks for your contribution!

Please follow the instructions below for each change. See also: https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md

Available commands

You can use the following commands by commenting on this PR.

  • /merge: Merge this PR if CI passes

activerecord

You changed RBS files for an existing gem. You need to get approval from the reviewers of this gem.

@hibariya, @ksss, @Little-Rubyist, please review this pull request. If this change is acceptable, please make a review comment including APPROVE from here. Screen Shot 2024-03-19 at 14 13 36

After that, the PR author or the reviewers can merge this PR. Just comment /merge to merge this PR.

github-actions[bot] avatar Oct 31 '24 02:10 github-actions[bot]

FYI: API doc mentions the return value of #delete_all.

Returns the number of rows affected. https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-delete_all

tk0miya avatar Oct 31 '24 04:10 tk0miya

I noticed ActiveRecord::Associations::CollectionProxy#delete_all takes an optional argument dependent. But ActiveRecord::Associations::Relation#delete_all does not take arguments at all.

But the current design of rbs_rails expects both to be the same. Therefore it's not good to modify definitions under activerecord.rbs (ActiveRecord::Relation::Methods, ActiveRecord::Base::ClassMethods, _ActiveRecord_Relation and _ActiveRecord_Relation_ClassMethods).

It's better to change only the return types of these methods under activerecord.rbs. And we need to hack rbs_rails to override the argument type of CollectionProxy#delete_all via rbs_rails like https://github.com/pocke/rbs_rails/pull/289 does.

Refs:

  • https://api.rubyonrails.org/classes/ActiveRecord/Associations/CollectionProxy.html#method-i-delete_all
  • https://api.rubyonrails.org/classes/ActiveRecord/Relation.html#method-i-delete_all

tk0miya avatar Nov 18 '24 17:11 tk0miya

Thank you for your valuable feedback. I apologize for not fully understanding the differences between ActiveRecord::Associations::CollectionProxy#delete_all and ActiveRecord::Associations::Relation#delete_all, as well as the specifics of rbs_rails.

In this pull request, I have only updated the return types. I will address the override of CollectionProxy#delete_all in rbs_rails separately.

If there are any remaining issues, please let me know.

k-in0ue avatar Nov 21 '24 00:11 k-in0ue

Sorry for the delay in responding.

  • When modifying 6.0/activerecord-generated.rbs, move as far as possible to 6.0/activerecord.rbs.
  • I would like at least one line of testing.

ksss avatar Dec 12 '24 07:12 ksss