Commit ec3acf86 authored by nmilojevic1's avatar nmilojevic1

Use only iis for quering merge request

parent 99fc1d06
......@@ -50,11 +50,11 @@ module Gitlab
].compact
end
# Returns Arel clause `"{table_name}"."project_id" = {project.id}`
# Returns Arel clause `"{table_name}"."project_id" = {project.id}` if project is present
# or, if group is present:
# `"{table_name}"."project_id" = {project.id} OR "{table_name}"."group_id" = {group.id}`
def where_clause_base
clause = table[project_column].eq(project.id)
clause = table[:project_id].eq(project.id) if project
clause = clause.or(table[:group_id].eq(group.id)) if group
clause
......@@ -108,14 +108,6 @@ module Gitlab
klass == MergeRequest
end
def project_column
if @original_klass.reflect_on_association(:project) || label?
:project_id
elsif klass.reflect_on_association(:target_project)
:target_project_id
end
end
# If an existing group milestone used the IID
# claim the IID back and set the group milestone to use one available
# This is necessary to fix situations like the following:
......
......@@ -332,16 +332,12 @@ module Gitlab
# Can't use IDs as validation exists calling `group` or `project` attributes
finder_hash = parsed_relation_hash.tap do |hash|
hash['group'] = @project.group if relation_class.attribute_method?('group_id')
hash['project'] = @project if reflect_on_project_association?
hash['project'] = @project if relation_class.reflect_on_association(:project)
hash.delete('project_id')
end
GroupProjectObjectBuilder.build(relation_class, finder_hash)
end
def reflect_on_project_association?
relation_class.reflect_on_association(:project) || relation_class.reflect_on_association(:target_project)
end
end
end
end
......@@ -55,23 +55,23 @@ describe Gitlab::ImportExport::GroupProjectObjectBuilder do
merge_request = create(:merge_request, title: 'MergeRequest', iid: 7, target_project: project, source_project: project)
expect(described_class.build(MergeRequest,
'title' => 'MergeRequest',
'project' => project,
'source_project_id' => project.id,
'target_project_id' => project.id,
'source_branch' => 'SourceBranch',
'iid' => 7,
'target_branch' => 'TargetBranch',
'author' => project.creator)).to eq(merge_request)
'author_id' => project.creator.id)).to eq(merge_request)
end
it 'creates a new merge_request' do
merge_request = described_class.build(MergeRequest,
'title' => 'MergeRequest',
'project' => project,
'iid' => 8,
'source_project' => project,
'source_project_id' => project.id,
'target_project_id' => project.id,
'source_branch' => 'SourceBranch',
'target_branch' => 'TargetBranch',
'author' => project.creator)
'author_id' => project.creator.id)
expect(merge_request.persisted?).to be true
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