Patch #20124

Query option, The sql for field to allow groups option.

Added by Rupesh J over 2 years ago. Updated over 1 year ago.

Status:NewStart date:
Priority:HighDue date:
Assignee:-% Done:

0%

Category:-
Target version:-

Description

The simple commit help abundantly and allow us to grouping the custom queries.
When the available filters is added with the field name, the check already exists for sql field statement.
Another check is added when the field is added with grouping.

Please update this patch in the core.

Thanks.

sql_for_fields_with_group-git.diff Magnifier (980 Bytes) Rupesh J, 2015-06-18 09:25

sql_for_fields_with_group-git-updated.patch Magnifier (995 Bytes) Rupesh J, 2016-02-18 15:12

History

#1 Updated by Rupesh J over 2 years ago

The advantage of this patch, is that I do not need to alias the sql_for_field method in my plugin!
I am also open for more elegant solution.
Thanks.

#2 Updated by Toshi MARUYAMA over 1 year ago

  • Status changed from New to Needs feedback

Where is $2 from?
field =~ /^(.+)\./ returns only $1.

#3 Updated by Rupesh J over 1 year ago

For the below cases, With grouping of filters,

Suppose, If I add a custom filter through a plugin patch

     add_available_filter("question.qassigned_to_id", :type => :list, :values => author_values,
         :caption => :field_question_assigned_to_id, :name => l(:field_question_assigned_to_id_esi)
     )

The only way to handle the corresponding SQL query is to alias the sql_for_field.
Instead if the attached patch is provided,
I can avoid the alias and also have my method,

    def sql_for_qassigned_to_id_field(.....)
      .... sql logic...
    end

Thank You.

#4 Updated by Toshi MARUYAMA over 1 year ago

In your sql_for_fields_with_group-git.diff

      elsif field =~ /^(.+)\./ && respond_to?("sql_for_#{$2}_field")
        # specific statement
        filters_clauses << send("sql_for_#{$2}_field", field, operator, v)

http://ruby-doc.org/core-2.1.1/Regexp.html#class-Regexp-label-Special+global+variables

$1, $2 and so on contain text matching first, second, etc capture group;

But your field =~ /^(.+)\./ has only one parenthesis.

#5 Updated by Rupesh J over 1 year ago

Yes, Realized my mistake. Thank You.
Here is the Updated patch.

Thanks.

#6 Updated by Toshi MARUYAMA over 1 year ago

  • Status changed from Needs feedback to New

Also available in: Atom PDF