Bug 18332 - Add the Koha::Objects->last method
Summary: Add the Koha::Objects->last method
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Architecture, internals, and plumbing (show other bugs)
Version: unspecified
Hardware: All All
: P5 - low enhancement (vote)
Assignee: Jonathan Druart
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks: 17964
  Show dependency treegraph
 
Reported: 2017-03-24 16:33 UTC by Jonathan Druart
Modified: 2017-12-07 22:18 UTC (History)
4 users (show)

See Also:
Change sponsored?: ---
Patch complexity: ---
Who signed the patch off:
Text to go in the release notes:
Version(s) released in:


Attachments
Bug 18332: Add the Koha::Objects->last method (4.25 KB, patch)
2017-03-24 16:45 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 18332: Add the Koha::Objects->last method (2.86 KB, patch)
2017-03-24 16:46 UTC, Jonathan Druart
Details | Diff | Splinter Review
Bug 18332: Add the Koha::Objects->last method (3.02 KB, patch)
2017-03-24 21:27 UTC, Marc Véron
Details | Diff | Splinter Review
Bug 18332: Add the Koha::Objects->last method (3.07 KB, patch)
2017-03-29 17:58 UTC, Tomás Cohen Arazi
Details | Diff | Splinter Review
Bug 18332: [QA Follow-up] Adjust slice call in last method (965 bytes, patch)
2017-03-31 07:34 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
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.