Commit 530cf2a2 authored by Bob Van Landuyt's avatar Bob Van Landuyt

Don't break when building unions on empty collections

parent 438a0773
......@@ -26,7 +26,11 @@ module Gitlab
@relations.map { |rel| rel.reorder(nil).to_sql }.reject(&:blank?)
end
fragments.join("\n#{union_keyword}\n")
if fragments.any?
fragments.join("\n#{union_keyword}\n")
else
'NULL'
end
end
def union_keyword
......
......@@ -29,5 +29,12 @@ describe Gitlab::SQL::Union do
expect(union.to_sql).to include('UNION ALL')
end
it 'returns `NULL` if all relations are empty' do
empty_relation = User.none
union = described_class.new([empty_relation, empty_relation])
expect(union.to_sql).to eq('NULL')
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