Skip to content

Commit

Permalink
replace from(nil) to from(Arel.sql(DUAL)) for to query from DUAL
Browse files Browse the repository at this point in the history
  • Loading branch information
ff2248 committed Sep 4, 2023
1 parent 74a2ca6 commit b9e16e5
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 @@ -88,7 +88,7 @@ def update_all_and_get_ids(*args)
@klass.transaction do
@relation.connection.execute('SET @ids := NULL')
@relation.where("(SELECT @ids := CONCAT_WS(',', #{id_column}, @ids))").update_all(*args) # 撈出有真的被更新的 id,用逗號串在一起
ids = @klass.from(nil).pluck(Arel.sql('@ids')).first
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'
end
Expand Down

0 comments on commit b9e16e5

Please sign in to comment.