Skip to content
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

Fix the calling `merge` method at first in a scope #25849

Merged
merged 1 commit into from Jul 20, 2016

Conversation

@suginoy
Copy link
Contributor

@suginoy suginoy commented Jul 15, 2016

Summary

Calling the merge method at first in a scope raises NoMethodError.

scope :unsafe_chaininig, -> { merge(Comment.newest) } #=> NoMethodError: undefined method `merge'

Other Information

Changing the order of method chaining merge and other query
method such as joins should produce the same result.

class Topic < ApplicationRecord
  scope :safe_chaininig,   -> { joins(:comments).merge(Comment.newest) } # => OK
  scope :unsafe_chaininig, -> { merge(Comment.newest).joins(:comments) } # => NoMethodError
end
@rails-bot
Copy link

@rails-bot rails-bot commented Jul 15, 2016

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @kaspth (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@rafaelfranca
Copy link
Member

@rafaelfranca rafaelfranca commented Jul 17, 2016

Could you add a CHANGELOG entry?

@suginoy suginoy force-pushed the suginoy:fix_merge_in_scope branch Jul 19, 2016
Changing the order of method chaining `merge` and other query
method such as `joins` should produce the same result.

```ruby
class Topic < ApplicationRecord
  scope :safe_chaininig,   -> { joins(:comments).merge(Comment.newest) }
  scope :unsafe_chaininig, -> { merge(Comment.newest).joins(:comments) } #=> NoMethodError
end
```
@suginoy suginoy force-pushed the suginoy:fix_merge_in_scope branch to cf2574b Jul 19, 2016
@suginoy
Copy link
Contributor Author

@suginoy suginoy commented Jul 19, 2016

@rafaelfranca Added the CHANGELOG entry. Thanks.

@rafaelfranca rafaelfranca merged commit cf2574b into rails:master Jul 20, 2016
2 checks passed
2 checks passed
codeclimate Code Climate didn't find any new or fixed issues.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
rafaelfranca added a commit that referenced this pull request Jul 20, 2016
Fix the calling `merge` method at first in a scope
@suginoy suginoy deleted the suginoy:fix_merge_in_scope branch Nov 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants
You can’t perform that action at this time.