View Issue Details

IDProjectCategoryView StatusLast Update
0009773mantisbtcustom fieldspublic2010-04-23 23:23
Reporterpramsent Assigned Todhx  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionduplicate 
Summary0009773: Sorting of two custom fields does not work
Description

I try to sort my view issue list by two custom fields and get an error message (see additional information)

Is there a patch or other possibility to get this working?

Is there a possibility to sort by more than two fields?

thanks - great work

Additional Information

APPLICATION ERROR 0000401
Database query failed. Error received from database was #1066: Not unique table/alias: 'mantis_custom_field_string_table' for the query: SELECT DISTINCT mantis_bug_table.*, mantis_custom_field_string_table.value
FROM mantis_bug_table
LEFT JOIN mantis_custom_field_string_table ON ( ( mantis_custom_field_string_table.bug_id = mantis_bug_table.id ) AND ( mantis_custom_field_string_table.field_id = 21 ) ) LEFT JOIN mantis_custom_field_string_table ON ( ( mantis_custom_field_string_table.bug_id = mantis_bug_table.id ) AND ( mantis_custom_field_string_table.field_id = 22 ) )
WHERE mantis_bug_table.id in (6562, 6598, 6848, 6863, 6866, 6867, 6868, 6869, 6870, 6880)
ORDER BY sticky DESC, mantis_custom_field_string_table.value DESC, mantis_custom_field_string_table.value ASC, last_updated DESC, date_submitted DESC

TagsNo tags attached.

Relationships

duplicate of 0005859 closeddaryn "Sort by" can't handle more than one custom field in combination 

Activities

pramsent

pramsent

2008-11-03 14:52

reporter   ~0019770

I'm using 1.1.1

meejiuus

meejiuus

2008-12-21 14:22

reporter   ~0020459

I've got the same problem with the so called "stable version" 1.1.6.

a similar report is this:
http://www.mantisbt.org/bugs/view.php?id=6661
where someone announced that there is a new filter_api that solves the problem. however that filter api belongs to another version and does not work with 1.1.6

in this thread a solution is suggested:
http://forums.mantisbt.org/viewtopic.php?f=3&t=2137&start=0&st=0&sk=t&sd=a

because that didn't work as well for me, i developed a new working solution:

just open
/mantis/core/filter_api.php

and search for the line:

if sorting by a custom field ## was error, now changed

if ( strpos( $csort, 'custom' ) === 0 ) {
$t_custom_field = substr( $csort, strlen( 'custom' ) );
$t_custom_field_id = custom_field_get_id_from_name( $t_custom_field );

and then replace this:
$t_join .= " LEFT JOIN $t_custom_field_string_table ON ( ( $t_custom_field_string_table.bug_id = $t_bug_table.id ) AND ( $t_custom_field_string_table.field_id = $t_custom_field_id ) )";

by THIS:
#==== WORKING: =======
$t_join = " LEFT JOIN $t_custom_field_string_table ON ( ( $t_custom_field_string_table.bug_id = $t_bug_table.id ) AND ( $t_custom_field_string_table.field_id = $t_custom_field_id ) )";

Have fun,

meejiuus

Chi-Yu

Chi-Yu

2009-05-20 06:48

reporter   ~0021863

This problem is still present in 1.1.7.

mantistestor

mantistestor

2009-05-28 06:48

reporter   ~0021953

still present in 1.2.0a3

mantistestor

mantistestor

2009-06-02 12:50

reporter   ~0022034

Workaround:
dont use - or other Signs in the Name of the fields.
Example:
noGo -> ok
no-Go -> not ok

_ Works!

Example:
no_Go -> ok

ghweb

ghweb

2009-07-30 06:14

reporter   ~0022608

Last edited: 2009-07-30 06:16

See issue 5859 for a better solution.
Solution from meejiuus will not consider the sorting of all custom fields columns.

ghweb

ghweb

2009-07-30 11:07

reporter   ~0022613

This can be solved with alias as tablenames:

In core\filter_api.php

Old Code:

if sorting by a custom field

            if ( strpos( $c_sort, 'custom_' ) === 0 ) {
                $t_custom_field = substr( $c_sort, strlen( 'custom_' ) );
                $t_custom_field_id = custom_field_get_id_from_name( $t_custom_field );
                $t_join .= " LEFT JOIN $t_custom_field_string_table ON ( ( $t_custom_field_string_table.bug_id = $t_bug_table.id ) AND ( $t_custom_field_string_table.field_id = $t_custom_field_id ) )";
                $c_sort = "$t_custom_field_string_table.value";
                $t_select_clauses[] = "$t_custom_field_string_table.value";
                }

New Code:

if sorting by a custom field

            if ( strpos( $c_sort, 'custom_' ) === 0 ) {
                $t_custom_field = substr( $c_sort, strlen( 'custom_' ) );
                $t_custom_field_id = custom_field_get_id_from_name( $t_custom_field );
                $t_join .= " LEFT JOIN $t_custom_field_string_table $t_custom_field_string_table$i ON ( ( $t_custom_field_string_table$i.bug_id = $t_bug_table.id ) AND ( $t_custom_field_string_table$i.field_id = $t_custom_field_id ) )";
                $c_sort = "$t_custom_field_string_table$i.value";
                $t_select_clauses[] = "$t_custom_field_string_table$i.value";
                }

Perhaps could you implement this in the next release.

Regards