30808-fix-child-id-filter.patch

Yuichi HARADA, 2019-02-19 03:14

Download (1.56 KB)

View differences:

app/models/issue_query.rb
510 510
  def sql_for_child_id_field(field, operator, value)
511 511
    case operator
512 512
    when "="
513
      parent_id = Issue.where(:id => value.first.to_i).pluck(:parent_id).first
514
      if parent_id
515
        "#{Issue.table_name}.id = #{parent_id}"
513
      # accepts a comma separated list of child ids
514
      child_ids = value.first.to_s.scan(/\d+/).map(&:to_i).uniq
515
      ids = Issue.where(:id => child_ids).pluck(:parent_id).compact.uniq
516
      if ids.present?
517
        "#{Issue.table_name}.id IN (#{ids.join(",")})"
516 518
      else
517 519
        "1=0"
518 520
      end
test/unit/query_test.rb
290 290
    assert_equal [2,4,5], issues.map(&:id).sort
291 291
  end
292 292

  
293
  def test_operator_is_on_child_id_should_accept_comma_separated_values
294
    Issue.where(:id => [2,4]).update_all(:parent_id => 1)
295
    Issue.where(:id => 5).update_all(:parent_id => 3)
296
    query = IssueQuery.new(:name => '_')
297
    query.add_filter("child_id", '=', ['2,4,5'])
298
    issues = find_issues_with_query(query)
299
    assert_equal 2, issues.size
300
    assert_equal [1,3], issues.map(&:id).sort
301
  end
302

  
293 303
  def test_operator_between_on_issue_id_should_return_range
294 304
    query = IssueQuery.new(:name => '_')
295 305
    query.add_filter("issue_id", '><', ['2','3'])