Skip to content

Commit

Permalink
Fix: Use explicit expression in where condition
Browse files Browse the repository at this point in the history
  • Loading branch information
glasses618 committed Aug 18, 2024
1 parent 48d54d5 commit eeac1c5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/atomically/query_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def update_all_and_get_ids(*args)
id_column = quote_column_with_table(:id)
@klass.transaction do
@relation.connection.execute('SET @ids := NULL')
@relation.where("(SELECT @ids := CONCAT_WS(',', #{id_column}, @ids))").update_all(*args) # 撈出有真的被更新的 id,用逗號串在一起
@relation.where("((@ids := CONCAT_WS(',', #{id_column}, @ids)) IS NOT NULL)").update_all(*args) # 撈出有真的被更新的 id,用逗號串在一起
ids = @klass.from(Arel.sql('DUAL')).pluck(Arel.sql('@ids')).first
end
return ids.try{|s| s.split(',').map(&:to_i).uniq.sort } || [] # 將 id 從字串取出來 @id 的格式範例: '1,4,12'
Expand Down

0 comments on commit eeac1c5

Please sign in to comment.