Commit 6864c1f2 authored by Mark Chao's avatar Mark Chao

Use union to get distinct project ids

parent 5d91db5b
...@@ -36,9 +36,14 @@ class MigrateProjectApprovers < ActiveRecord::Migration[5.0] ...@@ -36,9 +36,14 @@ class MigrateProjectApprovers < ActiveRecord::Migration[5.0]
private private
def get_project_ids def get_project_ids
project_ids = Approver.where('target_type = ?', 'Project').pluck(:target_id) results = ActiveRecord::Base.connection.exec_query <<~SQL
project_ids += ApproverGroup.where('target_type = ?', 'Project').pluck(:target_id) SELECT DISTINCT target_id FROM (
project_ids.uniq! SELECT target_id FROM approvers WHERE target_type='Project'
project_ids UNION
SELECT target_id FROM approver_groups WHERE target_type='Project'
) t
SQL
results.rows.flatten
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment