If you choose in filter relationship: "none to a bug " SQL is written in a wrong way.
It rather should be with NOT EXISTS, than with Joins to relationship table with COALESCE conditions.
So is:
$t_where = 'NOT COALESCE(' . $t_table_dst . '.source_bug_id, -1) = ' . $this->param( $c_rel_bug )
. ' AND NOT COALESCE(' . $t_table_src . '.destination_bug_id, -1) = ' . $this->param( $c_rel_bug )
. ' AND NOT {bug}.id = ' . $this->param( $c_rel_bug );
Should be:
$t_where = 'NOT EXISTS( SELECT 1 FROM {bug_relationship} WHERE source_bug_id = ' . $this->param( $c_rel_bug ) . ' AND destination_bug_id = {bug}.id'
. ' OR destination_bug_id = ' . $this->param( $c_rel_bug ) . ' AND source_bug_id = {bug}.id)';
Is:
$this->add_join( 'LEFT JOIN {bug_relationship} ' . $t_table_dst . ' ON ' . $t_table_dst . '.destination_bug_id = {bug}.id' );
$this->add_join( 'LEFT JOIN {bug_relationship} ' . $t_table_src . ' ON ' . $t_table_src . '.source_bug_id = {bug}.id' );
Should be:
if( BUG_REL_NONE != $c_rel_type || (META_FILTER_NONE == $c_rel_bug || META_FILTER_ANY == $c_rel_bug) ) {
$this->add_join( 'LEFT JOIN {bug_relationship} ' . $t_table_dst . ' ON ' . $t_table_dst . '.destination_bug_id = {bug}.id' );
$this->add_join( 'LEFT JOIN {bug_relationship} ' . $t_table_src . ' ON ' . $t_table_src . '.source_bug_id = {bug}.id' );
}
Example:
if bug A has relationship to B and C and you choose none relationship to B, A would be chosen, because of existing non-B = C relationship.
In NOT EXISTS A wouldn`t be chosen |