- 
                Notifications
    
You must be signed in to change notification settings  - Fork 92
 
Open
Description
Mobility Rails 8.0 Compatibility Issue - GitHub Issue Template
Environment
- Mobility version: 1.3.2
 - Rails version: 8.0.3
 - Ruby version: 3.3.3
 - Database: PostgreSQL
 
Description
The Rails 8.0 compatibility fix introduced in Mobility 1.3.2 (referencing PR #654 and #655) contains an incomplete implementation that causes a NoMethodError when select_values contains plain strings instead of Arel nodes.
Error
NoMethodError: undefined method `right' for an instance of String
Root Cause
The select_for_count method in lib/mobility/plugins/active_record/query.rb assumes all values in select_values respond to .right and .left methods (i.e., are Arel::Nodes::As objects):
if select_values.any? { |value| value.right.start_with?(ATTRIBUTE_ALIAS_PREFIX) }
  filtered_select_values = select_values.map do |value|
    value.right.start_with?(ATTRIBUTE_ALIAS_PREFIX) ? value.left : value
  end
  # ...
endHowever, as noted in PR #654's comments, Rails 8.0 changed behavior (commit: rails/rails@ba468db) such that select_values can contain plain strings like "id" instead of Arel nodes.
Steps to Reproduce
- Upgrade to Rails 8.0.x
 - Use Mobility 1.3.2
 - Perform any query that triggers 
select_for_countwith a simple select value - Observe the 
NoMethodErroron.right 
Proposed Fix
Check if values respond to .right before calling it:
Metadata
Metadata
Assignees
Labels
No labels