Browse Source

Allow complex filtering when only one level is set

When using complex filtering, one could use as filter argument ($values):
array(
  'fieldname' => array(
    'op' => 'someop',
    'data' => 'somevalue',
  ),
);

or

array(
  'fieldname' => array(
    array(
      'op' => 'someop',
      'data' => 'somevalue',
    ),
    array(
      'op' => 'someop2',
      'data' => 'somevalue2',
    ),
  ),
);

but the following syntax was not supported:
array(
  'fieldname' => array(
    array(
      'op' => 'someop',
      'data' => 'somevalue',
    ),
  ),
);

This last syntax should be supported as complex filters might be auto-generated by some process that should not have to worry, in the end, if they provide just one or several complex filters for a field.
This patch does the trick.
Valentin Guignon 6 years ago
parent
commit
2c64125287
1 changed files with 2 additions and 1 deletions
  1. 2 1
      tripal_chado/api/tripal_chado.query.api.inc

+ 2 - 1
tripal_chado/api/tripal_chado.query.api.inc

@@ -1367,7 +1367,8 @@ function chado_select_record($table, $columns, $values, $options = NULL) {
 
       // CASE 1a: If there is only one element in the array, treat it the same
       // as a non-array value.
-      if (count($value) == 1 AND is_int(key($value))) {
+      if (count($value) == 1 AND is_int(key($value))
+          AND !(isset($value[0]['op']) && isset($value[0]['op']))) {
 
         $value = array_pop($value);
         $op = '=';