Commit d8eebe1c authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch 'fix-ambiguous-query-error' into 'master'

Fix ambiguous query error on milestone_id

See merge request gitlab-org/gitlab!37451
parents bf8eadf2 7e7c7029
......@@ -15,7 +15,7 @@ module Milestoneable
validate :milestone_is_valid
scope :of_milestones, ->(ids) { where(milestone_id: ids) }
scope :any_milestone, -> { where('milestone_id IS NOT NULL') }
scope :any_milestone, -> { where.not(milestone_id: nil) }
scope :with_milestone, ->(title) { left_joins_milestones.where(milestones: { title: title }) }
scope :without_particular_milestone, ->(title) { left_outer_joins(:milestone).where("milestones.title != ? OR milestone_id IS NULL", title) }
scope :any_release, -> { joins_milestone_releases }
......
---
title: Fix ambiguous query error when filtering for Any milestone in Value Stream
Analytics
merge_request: 37451
author:
type: fixed
......@@ -103,7 +103,7 @@ RSpec.describe Milestoneable do
end
describe 'release scopes' do
let_it_be(:project) { create(:project) }
let_it_be(:project) { create(:project, :repository) }
let_it_be(:release_1) { create(:release, tag: 'v1.0', project: project) }
let_it_be(:release_2) { create(:release, tag: 'v2.0', project: project) }
......@@ -126,6 +126,22 @@ RSpec.describe Milestoneable do
let_it_be(:items) { Issue.all }
describe '#any_milestone' do
context 'when milestone filter is present and related closing issues are joined' do
let_it_be(:merge_request_1) { create(:merge_request, source_project: project, source_branch: 'feature-1') }
let_it_be(:merge_request_2) { create(:merge_request, source_project: project, source_branch: 'feature-2') }
let_it_be(:mrc_issue_1) { create(:merge_requests_closing_issues, issue: issue_1, merge_request: merge_request_1) }
let_it_be(:mrc_issue_2) { create(:merge_requests_closing_issues, issue: issue_2, merge_request: merge_request_2) }
it 'returns merge request closing issues of any milestone' do
relation = items.joins(merge_requests_closing_issues: :issue).any_milestone
expect(relation).to contain_exactly(issue_1, issue_2)
end
end
end
describe '#without_release' do
it 'returns the issues not tied to any milestone and the ones tied to milestone with no release' do
expect(items.without_release).to contain_exactly(issue_5, issue_6)
......
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