Methods defined on `PrivateRelation` should return `T.self_type`
Maintainers usually reply within 3 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start by examining the relevant compilers that add methods to PrivateRelation and the model, then trace how the return type for .all is generated. Verify the behavior against the Kaminari example, including chaining .all and preserving the extended relation methods. Done means the generated type reflects the relation's self type without losing methods added to the model.
Written by the indexing model from the issue text.
Description
I wrote a compiler for Kaminari that returns the following:
sig { T.all(PrivateRelation, Kaminari::PageScopeMethods, Kaminari::ActiveRecordRelationMethods) }
def page(num = nil); end
This type is accurate, since .page uses .extending to add methods to the relation.
This works:
User.page(5).total_count
This doesn't work:
User.page(5).all.total_count
^^^^^^^^^^^ Method `total_count` does not exist on `User::PrivateRelation`
That's because the return type of for .all is PrivateRelation. We could fix this problem by using T.self_type instead, which I believe more accurately captures the way ActiveRecord works.
The way that relevant compilers are currently implemented makes this a little tricky, since the methods that are being added to the PrivateRelation are also added to the model. The methods defined on the model should be PrivateRelation.
- Dominant language
- Ruby
- Stars
- 874
- Forks
- 165
- Avg merge
- 3d 30m
- Merged PRs (30d)
- 7
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Shopify/tapioca
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Shopify/tapioca#2662 · 1 comment ·
Maintainers usually reply within 3 days
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Maintainers usually reply within 3 days
-
Improve `check-shims` performancePossibly taken @KaanOzkan claimed this 2 days ago. Open
Shopify/tapioca#2728 · 1 assignee ·
Maintainers usually reply within 3 days
-
ActiveRecordRelations cannot generate an RBI for an Active Record model with a composite primary keyOpen
Difficulty 3/5 1-2 days Newbie friendliness 76/100
Maintainers usually reply within 3 days
-
Difficulty 5/5 Over a week Newbie friendliness 30/100
Maintainers usually reply within 3 days
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
security
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
ds-drift
Difficulty 1/5 Under an hour Newbie friendliness 88/100
we-promise/sure#3934 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100
hanami/hanami-view#287 · 3 comments ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day