Bug 24432: Use from_api_mapping to translate column name in _build_order_atom
authorAgustin Moyano <agustinmoyano@theke.io>
Wed, 15 Jan 2020 23:12:19 +0000 (20:12 -0300)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Thu, 23 Jan 2020 08:53:01 +0000 (08:53 +0000)
Use the mapping instead of building a fake hash only to get the key name.

To test:
1. apply this patch
2. prove t/Koha/REST/Plugin/Query.t
3. sign off

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Koha/REST/Plugin/Query.pm

index 3317348..b2ebd8f 100644 (file)
@@ -220,7 +220,8 @@ sub _build_order_atom {
     my $param = $string;
     $param =~ s/^(\+|\-|\s)//;
     if ( $result_set ) {
-        $param = (keys %{$result_set->attributes_from_api({ $param => 1 })})[0];
+        my $model_param = $result_set->from_api_mapping->{$param};
+        $param = $model_param if defined $model_param;
     }
 
     if ( $string =~ m/^\+/ or