Skip to content

Conversation

@rhiroe
Copy link
Contributor

@rhiroe rhiroe commented Jan 30, 2026

Problem

Currently, load_async is defined to return ActiveRecord::Relation[Model]. This creates a technical inconsistency because most other relation methods (such as where, all, and order) return Model::ActiveRecord_Relation.

Although these represent the same runtime object, RBS treats them as distinct types. This forces users to unnecessarily distinguish between them when handling return values or defining method signatures, even though consistency with other common methods is expected.

Concerns

This is a breaking change. It will cause type mismatches in projects where other RBS definitions are written assuming load_async returns ActiveRecord::Relation[Model]. However, I believe unifying the return type with the standard Model::ActiveRecord_Relation significantly improves DX and reduces confusion across the RBS ecosystem.

What are your thoughts on this change?

Update `load_async` to return `self` instead of the explicit
`ActiveRecord::Relation[Model]`.

While both represent the same runtime object, RBS treats them as
distinct types from `Model::ActiveRecord_Relation` (returned by
methods like `where` or `all`). This discrepancy causes type
mismatches and forces unnecessary type distinctions during method
chaining or when defining signatures. Changing it to `self` ensures
consistency with other relation methods.
@rhiroe rhiroe marked this pull request as ready for review January 30, 2026 01:47
@github-actions
Copy link

@rhiroe 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, @tk0miya, 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.

@rhiroe
Copy link
Contributor Author

rhiroe commented Jan 30, 2026

@dak2 Since you were the one who originally added the types for this method, I believe this change will affect your work. I'd love to get your thoughts on this.

@dak2
Copy link
Contributor

dak2 commented Jan 30, 2026

@rhiroe

Currently, load_async is defined to return ActiveRecord::Relation[Model]. This creates a technical inconsistency because most other relation methods (such as where, all, and order) return Model::ActiveRecord_Relation.

Exactly.

@dak2 Since you were the one who originally added the types for this method, I believe this change will affect your work. I'd love to get your thoughts on this.

In my case, the impact was minimal because I only used it partially.
So, I approve of your suggestions. Thanks!

@rhiroe
Copy link
Contributor Author

rhiroe commented Jan 30, 2026

/merge

@github-actions
Copy link

/merge command failed.

This PR is not approved yet by the reviewers. Please get approval from the reviewers.

See the Actions tab for detail.

Copy link
Collaborator

@ksss ksss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVE

@github-actions
Copy link

Thanks for your review, @ksss!

@rhiroe, @ksss This PR is ready to be merged.
Just comment /merge to merge this PR.

@rhiroe
Copy link
Contributor Author

rhiroe commented Jan 30, 2026

/merge

@github-actions github-actions bot merged commit 5aeae33 into ruby:main Jan 30, 2026
8 checks passed
@rhiroe rhiroe deleted the change/load_async-return-type-to-self branch January 30, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants