| 1 |
NAME |
| 2 |
Class::DBI::Plugin::RetrieveAll - more complex retrieve_all() for |
| 3 |
Class::DBI |
| 4 |
|
| 5 |
SYNOPSIS |
| 6 |
use base 'Class::DBI'; |
| 7 |
use Class::DBI::Plugin::RetrieveAll; |
| 8 |
|
| 9 |
my @by_date = My::Class->retrieve_all_sorted_by("date"); |
| 10 |
|
| 11 |
# or |
| 12 |
|
| 13 |
__PACKAGE__->retrieve_all_sort_field('date'); |
| 14 |
|
| 15 |
my @by_date = My::Class->retrieve_all; |
| 16 |
|
| 17 |
DESCRIPTION |
| 18 |
This is a simple plugin to a Class::DBI subclass that allows for simple |
| 19 |
sorting of the results of a retrieve_all(). |
| 20 |
|
| 21 |
There are two main ways to use this. |
| 22 |
|
| 23 |
Firstly, we create a new method 'retrieve_all_sorted_by' which takes an |
| 24 |
argument of how to sort. |
| 25 |
|
| 26 |
We also add a method for 'retrieve_all_sort_field' that sets a default |
| 27 |
field that any retrieve_all() will use for sorting. |
| 28 |
|
| 29 |
METHODS |
| 30 |
retrieve_all_sorted_by |
| 31 |
my @by_date = My::Class->retrieve_all_sorted_by("date"); |
| 32 |
|
| 33 |
This method will be exported into the calling class, and allows for |
| 34 |
retrieving all the objects of the class, sorted by the given column. |
| 35 |
|
| 36 |
The argument given will be passed straight through to the database 'as |
| 37 |
is', and is not checked in any way, so an error here will usually in an |
| 38 |
error from the database, rather than Class::DBI itself. |
| 39 |
|
| 40 |
This makes it possible to pass more complex ORDER BY clauses through: |
| 41 |
|
| 42 |
my @by_date = My::Class->retrieve_all_sorted_by("date DESC, reference_no"); |
| 43 |
|
| 44 |
retrieve_all_sort_field |
| 45 |
__PACKAGE__->retrieve_all_sort_field('date'); |
| 46 |
|
| 47 |
This method changes the default retrieve_all() in the Class to be |
| 48 |
auto-sorted by the field given. Again this will be passed through |
| 49 |
directly, so you can have complex ORDER BY clauses. |
| 50 |
|
| 51 |
AUTHOR |
| 52 |
Tony Bowden |
| 53 |
|
| 54 |
BUGS and QUERIES |
| 55 |
Please direct all correspondence regarding this module to: |
| 56 |
[email protected] |
| 57 |
|
| 58 |
COPYRIGHT and LICENSE |
| 59 |
Copyright (C) 2004-2006 Kasei. All rights reserved. |
| 60 |
|
| 61 |
This module is free software; you can redistribute it and/or modify it |
| 62 |
under the same terms as Perl itself. |
| 63 |
|