handling for string columns in Rails 8 #679
Open
+60
−11
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.
Description
Fixes a bug in
select_for_count(Rails 8.0+) where calling.rightonselect_values crashes when the array contains plain strings instead of
Arel nodes.
The Problem
When using Mobility with Rails 8.0+ and calling
.counton a query withselected columns, the code assumes all
select_valuesareArel::Nodes::Asobjects with a
.rightmethod. However, select_values can contain a mix ofplain strings (like
"id") and Arel nodes, causing:The Solution
Added
respond_to?(:right)checks before calling.righton select_valuesto safely handle both strings and Arel nodes.
Changes Made
respond_to?(:right)checks inselect_for_countmethodTest Results
All existing tests pass, plus 3 new tests:
# Rails 8.0 with Ruby 3.2.5 15 examples, 0 failuresRelated Issues
Closes #678
Related to
selectwith noorderclause #659 (comment)