diff options
author | Robert Speicher <robert@gitlab.com> | 2016-03-15 16:25:02 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2016-03-15 16:25:02 +0000 |
commit | 178c80a561fa10a157bae6e5d4682b232ae727c7 (patch) | |
tree | d1c6e3116acc6d5f628ee1f8a37cdac5840dc24e | |
parent | 09494ff413b342884f8df9d8385a71b6ec820688 (diff) | |
parent | c742760289e51117d3e76e27a626691bec631e1e (diff) | |
download | gitlab-ce-178c80a561fa10a157bae6e5d4682b232ae727c7.tar.gz |
Merge branch 'fix-activerecord-join-stupidity' into 'master'
Ignore eager loading in Project.search UNION
This fixes issues such as filtering groups by names on pages such as
https://gitlab.com/dashboard/groups.
See merge request !3229
-rw-r--r-- | app/models/project.rb | 7 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 6 |
2 files changed, 13 insertions, 0 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 346cd6222cf..89a55a510cd 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -286,7 +286,14 @@ class Project < ActiveRecord::Base or(ptable[:description].matches(pattern)) ) + # We explicitly remove any eager loading clauses as they're: + # + # 1. Not needed by this query + # 2. Combined with .joins(:namespace) lead to all columns from the + # projects & namespaces tables being selected, leading to a SQL error + # due to the columns of all UNION'd queries no longer being the same. namespaces = select(:id). + except(:includes). joins(:namespace). where(ntable[:name].matches(pattern)) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 59c5ffa6b9c..b8b9a455b83 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -634,6 +634,12 @@ describe Project, models: true do it 'returns projects with a matching namespace name regardless of the casing' do expect(described_class.search(project.namespace.name.upcase)).to eq([project]) end + + it 'returns projects when eager loading namespaces' do + relation = described_class.all.includes(:namespace) + + expect(relation.search(project.namespace.name)).to eq([project]) + end end describe '#rename_repo' do |