Bug 24191: Add to_model param to _build_order_atom and dbic_merge_sorting
authorTomas Cohen Arazi <tomascohen@theke.io>
Mon, 9 Dec 2019 17:48:48 +0000 (14:48 -0300)
committerLucas Gass <lucas@bywatersolutions.com>
Mon, 6 Jan 2020 20:49:46 +0000 (20:49 +0000)
commitd9ec59f191f8256e6961af290eb35cae673298e9
treef45b825844f74d59ce91150a57a07c83c59cb20e
parent99ad6cac3068621ff72c02f4f7ae4916124f52d5
Bug 24191: Add to_model param to _build_order_atom and dbic_merge_sorting

This patch adds a to_model parameter to dbic_merge_sorting so it is
passed when used (for example from objects.search). The to_model param
is passed along to the _build_order_atom method where it is finally
used.

In the process I wrote tests that reflected some problems in the current
code:
- Mojolicious automatically returns a scalar if a query parameter only
happens once on a request. The code expected an arrayref in every case.
- There's a design issue that forced me to use some hacky code in
_build_order_atom.

The first issue is dealth with, by using Scalar::Util::reftype as the
Perl docs recommend.

The second issue, I don't plan to clean it here, as there's ongoing work
on a Koha::Objects->search_from_api method that will obsolete this code
most probably (see bug 23893 for a better picture of where the mappings
will be living soon).

To test:
1. Apply this patch
2. Run:
  $ kshell
 k$ prove t/Koha/REST/Plugin/Query.t
=> SUCCESS: Tests pass!!
3. Sign off :-D

Sponsored-by: ByWater Solutions
Signed-off-by: Owen Leonard <oleonard@myacpl.org>
Signed-off-by: Josef Moravec <josef.moravec@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Joy Nelson <joy@bywatersolutions.com>
(cherry picked from commit 46895911d4668c343446104df41afb151dd2fae3)

Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
Koha/REST/Plugin/Query.pm
t/Koha/REST/Plugin/Query.t