Remove the magic :chain parameter from Relation#where#39784
Merged
rafaelfranca merged 1 commit intorails:masterfrom Oct 9, 2020
Merged
Remove the magic :chain parameter from Relation#where#39784rafaelfranca merged 1 commit intorails:masterfrom
:chain parameter from Relation#where#39784rafaelfranca merged 1 commit intorails:masterfrom
Conversation
(An alternative would be to use a constant like `Enumerable#index_with`)
|
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
Member
|
This broke basic chaining: >> Account.first.contacts.where.not(email_address: "1")
Account Load (1.9ms) SELECT `accounts`.* FROM `accounts` ORDER BY `accounts`.`id` ASC LIMIT 1
Traceback (most recent call last):
2: from (irb):4
1: from (irb):5:in `rescue in irb_binding'
ArgumentError (Unsupported argument type: chain (Symbol))Going to revert. |
Member
|
Egg on my face. We've been developing an encryption extension to Active Record that's enroute for upstreaming. But it overwrote the old where signature, which caused the failure. I've reverted the revert. Sorry for the drama! |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Removes the magic
:chainparameter fromRelation#where.It appears to be unnecessary as this method is either called with no parameters (as in
where.not) or with valid parameters.No functionality is changed
Motivation
Magic parameters are bad. In this case it makes it hard to extend the method as there is no guarantee that
:chainwould never be a valid argument. Say I wanted to write an extension with syntaxwhere(:title).like('%rails%')- that would break as soon as someone had a database field called:chainOther Information
Although I prefer avoiding magic parameters where unnecessary, the alternative is to use the object constant pattern used elsewhere in Rails. Something like
though, IMO, this makes the method harder to extend than simply not having it at all