Skip to content

Commit

Permalink
Merge pull request #25 from glasses618/fix/user_variable_in_where_con…
Browse files Browse the repository at this point in the history
…dition

Fix: Use explicit expression in where condition
  • Loading branch information
khiav223577 committed Sep 9, 2024
2 parents 48d54d5 + eeac1c5 commit 5a63dc7
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 5a63dc7

Please sign in to comment.