Project

General

Profile

Feature #30482 ยป 30482-fix-parent-id-filter.patch

Yuichi HARADA, 2019-01-31 09:00

View differences:

app/models/issue_query.rb
486 486
  def sql_for_parent_id_field(field, operator, value)
487 487
    case operator
488 488
    when "="
489
      "#{Issue.table_name}.parent_id = #{value.first.to_i}"
489
      # accepts a comma separated list of ids
490
      ids = value.first.to_s.scan(/\d+/).map(&:to_i).uniq
491
      if ids.present?
492
        "#{Issue.table_name}.parent_id IN (#{ids.join(",")})"
493
      else
494
        "1=0"
495
      end
490 496
    when "~"
491 497
      root_id, lft, rgt = Issue.where(:id => value.first.to_i).pluck(:root_id, :lft, :rgt).first
492 498
      if root_id && lft && rgt
test/unit/query_test.rb
280 280
    assert_equal [1,3], issues.map(&:id).sort
281 281
  end
282 282

  
283
  def test_operator_is_on_patient_id_should_accept_comma_separated_values
284
    Issue.where(:id => [2,4]).update_all(:parent_id => 1)
285
    Issue.where(:id => 5).update_all(:parent_id => 3)
286
    query = IssueQuery.new(:name => '_')
287
    query.add_filter("parent_id", '=', ['1,3'])
288
    issues = find_issues_with_query(query)
289
    assert_equal 3, issues.size
290
    assert_equal [2,4,5], issues.map(&:id).sort
291
  end
292

  
283 293
  def test_operator_between_on_issue_id_should_return_range
284 294
    query = IssueQuery.new(:name => '_')
285 295
    query.add_filter("issue_id", '><', ['2','3'])
    (1-1/1)