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

Add reselect method #33611

Merged
merged 8 commits into from Mar 1, 2019
Merged

Add reselect method #33611

merged 8 commits into from Mar 1, 2019

Conversation

willianveiga
Copy link
Contributor

@willianveiga willianveiga commented Aug 14, 2018

Allows you to change a previously set select statement:

Post.select(:title, :body).reselect(:created_at) # SELECT `posts.created_at` FROM `posts`

This is short-hand for unscope(:select).select(fields).

Note that we're unscoping the entire select statement.

def reselect(*fields)
  unscope(:select).select(*fields)
end

We already have rewhere and reorder. @brchristian said in #27340: "... I find it a helpful syntax to have, especially after getting used to the feel of the other two ..."

@rails-bot
Copy link

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @pixeltrix (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.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@dillonwelch
Copy link
Contributor

Never thought of that before but super cool idea. LGTM after a changelog entry! 👍

@willianveiga
Copy link
Contributor Author

Never thought of that before but super cool idea. LGTM after a changelog entry!

Done, @oniofchaos. Thank you very much! 😄

@simi
Copy link
Contributor

simi commented Oct 3, 2018

I think it will be great to mention this next to rewhere and reorder in ActiveRecord overriding conditions guides.

@rails-bot rails-bot bot added the docs label Oct 5, 2018
@willianveiga
Copy link
Contributor Author

I've made it, @simi. Thank you very much! 😃

@dcangulo
Copy link
Contributor

dcangulo commented Oct 5, 2018

When will this get merged?

@dillonwelch
Copy link
Contributor

Sadly there's a changelog merge conflict 😭

@willianveiga
Copy link
Contributor Author

Sadly there's a changelog merge conflict

Not anymore! 😄

@g1938703
Copy link

What about now, @oniofchaos? When will it be merged?

@dillonwelch
Copy link
Contributor

@g1938703 as I am not a maintainer I do not have merge capabilities. I am just helping out by providing reviews and commentary on PRs. It's ultimately up to that group, such as the assignee pixeltrix, when and if the PR gets merged.

Also, there's another merge conflict on the changelog :D

@willianveiga
Copy link
Contributor Author

@oniofchaos, nice job helping people out! 😃

@pixeltrix, when will this get merged?

Thank you very much, guys!

@pixeltrix
Copy link
Contributor

@willianveiga looking at the implementation for reorder and rewhere it seems to me that an implementation similar to reorder is more appropriate - unscope(:select).select(args) will create an extra relation instance compared to how reorder does it. The rewhere can't do it in the same way because it can redo a subset of conditions whereas reorder doesn't and reselect is the same.

@willianveiga
Copy link
Contributor Author

Is that what you meant, @pixeltrix?

Thank you very much, Wilian.

@ericgulini
Copy link

When will it be merged? Thank you!

@bobbytables
Copy link

Is this ever going to be merged?

@sikachu sikachu requested a review from pixeltrix March 1, 2019 02:38
@pixeltrix pixeltrix merged commit 0c4bf98 into rails:master Mar 1, 2019
@pixeltrix
Copy link
Contributor

@willianveiga thanks! 👍

Fixes #27340.

*Willian Gustavo Veiga*

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be great to move this changelog entry to the top of the file to point that this method will be available since the next Rails release.

@willianveiga willianveiga deleted the feature/reselect-method branch March 1, 2019 10:30
suketa added a commit to suketa/rails_sandbox that referenced this pull request Aug 31, 2019
Add reselect method
rails/rails#33611
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet