Bug 18332

Summary: Add the Koha::Objects->last method
Product: Koha Reporter: Jonathan Druart <jonathan.druart>
Component: Architecture, internals, and plumbingAssignee: Jonathan Druart <jonathan.druart>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: katrin.fischer, kyle, m.de.rooy, veron
Version: unspecified   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Bug Depends on:    
Bug Blocks: 17964    
Attachments: Bug 18332: Add the Koha::Objects->last method
Bug 18332: Add the Koha::Objects->last method
Bug 18332: Add the Koha::Objects->last method
Bug 18332: Add the Koha::Objects->last method
Bug 18332: [QA Follow-up] Adjust slice call in last method

Description Jonathan Druart 2017-03-24 16:33:16 UTC
This is not a DBIx::Class method, but we can provide it for Koha::Objects using slice.
Comment 1 Jonathan Druart 2017-03-24 16:45:43 UTC
Created attachment 61625 [details] [review]
Bug 18332: Add the Koha::Objects->last method

DBIx::Class does not provide such method, but it can be handy in some
cases.

Test plan:
  prove t/db_dependent/Koha/Objects.t
should return green
Comment 2 Jonathan Druart 2017-03-24 16:46:46 UTC
Created attachment 61626 [details] [review]
Bug 18332: Add the Koha::Objects->last method

DBIx::Class does not provide such method, but it can be handy in some
cases.

Test plan:
  prove t/db_dependent/Koha/Objects.t
should return green
Comment 3 Marc Véron 2017-03-24 21:27:12 UTC
Created attachment 61636 [details] [review]
Bug 18332: Add the Koha::Objects->last method

DBIx::Class does not provide such method, but it can be handy in some
cases.

Test plan:
  prove t/db_dependent/Koha/Objects.t
should return green

Test returned green.
Signed-off-by: Marc Véron <veron@veron.ch>
Comment 4 Tomás Cohen Arazi 2017-03-29 17:58:49 UTC
Created attachment 61694 [details] [review]
Bug 18332: Add the Koha::Objects->last method

DBIx::Class does not provide such method, but it can be handy in some
cases.

Test plan:
  prove t/db_dependent/Koha/Objects.t
should return green

Test returned green.
Signed-off-by: Marc Véron <veron@veron.ch>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Comment 5 Marcel de Rooy 2017-03-31 07:34:46 UTC
+    my $result = $self->_resultset->slice($count - 1, $count)->first;

Why do not do this:
    my ( $result ) = $self->_resultset->slice($count - 1, $count - 1);

Strictly speaking, you call slice with an invalid argument; since the index starts at 0, $count is past the last element.
Instead of calling in scalar context and doing first, you should call in list context?
Adding a follow-up.
Comment 6 Marcel de Rooy 2017-03-31 07:34:57 UTC
Created attachment 61751 [details] [review]
Bug 18332: [QA Follow-up] Adjust slice call in last method

We should call slice in list context with the correct indexes.

Test plan:
Run t/db_dependent/Koha/Objects.t

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 7 Kyle M Hall 2017-03-31 12:01:33 UTC
Pushed to master for 17.05, thanks Jonathan, Marcel!
Comment 8 Katrin Fischer 2017-04-02 16:31:04 UTC
This won't get ported back to 16.11.x as it is an enhancement.