-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add hash return type for relation groupchain size #2044
Open
marknuzz
wants to merge
1
commit into
Shopify:main
Choose a base branch
from
NuzzContribs:marknuzz/relations-compiler-group-size
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason to not add
:size
into theCALCULATION_METHODS
array itself?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm I'm actually not sure how to categorize this. These arrays are mostly organized based on the class that they were defined in, except the methods defined on
ActiveRecord::Relation
, where we haveFIND_OR_CREATE_METHODS
,BUILDER_METHODS
, andTO_ARRAY_METHODS
. But:size
(like:to_a
) is not something you can call directly on the model's class, so we can't have it inCommonRelationMethods
orGeneratedRelationMethods
. Unlike:to_a
,:size
's return type is different depending on context, so it didn't seem to fit into any of the above arrays.But now that you bring it up, this seems like one of those cases where the method name doesn't fit nicely into into an array and the method should be defined outside of the scope of the case statement looped over an array.
And when looking into how the
.to_a
worked, I'm now finding that theGeneratedRelationMethods#where
chain typing is actually incorrect. If you give an argument likeUser.where(foo: 1)
you do not in fact get to use the methods on thePrivateAssociationRelationWhereChain
returned. Additionally, you can't call:to_a
on an object that is a where chain (User.where.not.to_a
), unlike what the generated rbi suggests.I think the best thing to do here might be to take a step back and make sure this structure is actually correct, and to figure out a way to automatically test this so that this can't happen. This PR might be a symptom of a larger problem and could complicate things further, and the
.to_a
additions were a reasonably good example of a case where this happened due to the assumption that the existing behavior was correct, when it wasn't. Should we close this for now or what do you think?And now I can fully appreciate how difficult the job is of the Tapioca team!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Mark!
That seems reasonable to me.
I can't test this right now, could you explain the issue?
Haha thanks! Trying to tame Ruby meta-programming with types is a formidable challenge :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd much rather see
size
explicitly handled separately, since it is not a calculation method. Moreover, the signature generated forsize
in this PR is not correct, sincesize
does not take any parameters likecolumn_name
nor does it take a block.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding this:
Ufuk has opened a PR to make "where chains" no longer be relations: #2070