union operation broken in 9.0.0
aqeelvn opened this issue · 1 comments
aqeelvn commented
I was updating our rails app to 5.2.0
and hence arel
from 8.0.0
to 9.0.0
The union operation seems to be broken( even though its only deprecated in 9.0.0 ).
Here is an example of what the issue is:
left
and right
are two ActiveRecord
query objects. Individually they work, but left.union(right)
is breaking now in 9.0.0
.
left.to_sql
#=> "SELECT *, 1 as priority FROM `notifications` WHERE `notifications`.`receiver_id` = <masked> AND `notifications`.`read_at` IS NULL AND `notifications`.`target_type` = 'photo_type' AND `notifications`.`created_at` > '2018-04-09 10:11:12.732444'"
right.to_sql
#=> "SELECT *, 2 as priority FROM `notifications` WHERE `notifications`.`receiver_id` = <masked> AND `notifications`.`target_type` IN ('type1', 'type2', 'type3', 'type4') AND 1=1"
left.union(right).to_sql
#DEPRECATION WARNING: Delegating union to arel is deprecated and will be removed in Rails 6.0. (called from build_union_query at (pry):20)
#DEPRECATION WARNING: Delegating ast to arel is deprecated and will be removed in Rails 6.0. (called from build_union_query at (pry):20)
#=> "( SELECT *, 1 as priority FROM `notifications` WHERE `notifications`.`receiver_id` = <masked> AND `notifications`.`read_at` IS NULL AND `notifications`.`target_type` = 'photo_type' AND `notifications`.`created_at` > '2018-04-09 10:11:12.732444' UNION SELECT *, 2 as priority FROM `notifications` WHERE `notifications`.`receiver_id` = <masked> AND `notifications`.`target_type` IN (?, ?, ?, ?) AND 1=1 )"
As can be seen the generated SQL is invalid at this point:
`notifications`.`target_type` IN (?, ?, ?, ?)
matthewd commented
Per #523, Arel development is moving to rails/rails.
If this issue is still relevant, please consider reopening it over there. (Note that the Rails repository does not accept feature request issues, and requires reproduction steps that rely on Active Record's documented API.)