]> git.koha-community.org Git - koha.git/commit
Bug 19686: Add objects.search a 'to_model' param
authorTomas Cohen Arazi <tomascohen@theke.io>
Thu, 23 Nov 2017 20:10:42 +0000 (17:10 -0300)
committerJonathan Druart <jonathan.druart@bugs.koha-community.org>
Fri, 16 Feb 2018 17:05:20 +0000 (14:05 -0300)
commit4bd62d0a8c5f78d31ef12fdca856af76bdf13809
tree5d6615db385b046656210964eeb514e1bd3fcfd7
parent37ed1111cee60c519f844c789d4385eacd299fbb
Bug 19686: Add objects.search a 'to_model' param

This patch introduces a new parameter to the objects.search Mojo helper.
The idea behind this, is that if there's any attribute name mapping
between the DB objects and the API exposed ones, we should be able to
pass it to objects.search so the filtering query params are mapped
correctly for building the DBIC query, like this example:

  my $patrons_set = Koha::Patrons->new;
  my @patrons = $c->objects->search( $patrons_set,
                                     \&to_model
                                    )->as_list;
  # and probably
  @patrons = map {to_api($_)} @patrons;

The to_model function needs to avoid autovivification, to prevent
messing with the query parameters (undef params).

To test:
- Apply this patches
- Run:
  $ kshell
 k$ prove t/db_dependent/Koha/REST/Plugin/Objects.t
=> SUCCESS: Tests pass! Params get mapped!
- Sign off :-D

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: David Bourgault <david.bourgault@inlibro.com>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
Koha/REST/Plugin/Objects.pm