man Class::DBI::Plugin::RetrieveAll () - more complex retrieve_all() for Class::DBI

NAME

Class::DBI::Plugin::RetrieveAll - more complex retrieve_all() for Class::DBI

SYNOPSIS

        use base 'Class::DBI';
        use Class::DBI::Plugin::RetrieveAll;

        my @by_date = My::Class->retrieve_all_sorted_by("date");

        # or

        __PACKAGE__->retrieve_all_sort_field('date');

        my @by_date = My::Class->retrieve_all;

DESCRIPTION

This is a simple plugin to a Class::DBI subclass which allows for simple sorting of retrieve_all calls. There are two main ways to use this. Firstly, we create a new method 'retrieve_all_sorted_by' which takes an argument of how to sort. We also add a way to set a default field that any retrieve_all() should use to sort by.

METHODS

retrieve_all_sorted_by

        my @by_date = My::Class->retrieve_all_sorted_by("date");

This method will be exported into the calling class, and allows for retrieving all the objects of the class, sorted by the given column.

The argument given will be passed straight through to the database 'as is', and is not checked in any way, so an error here will probably result in an error from the database, rather than Class::DBI itself. However, because of this it is possible to pass more complex ORDER BY clauses through:

        my @by_date = My::Class->retrieve_all_sorted_by("date DESC, reference_no");

retrieve_all_sort_field

  __PACKAGE__->retrieve_all_sort_field('date');

This method changes the default retrieve_all() in the Class to be auto-sorted by the field given. Again this will be passed through directly, so you can have complex ORDER BY clauses.

AUTHOR

Tony Bowden

BUGS and QUERIES

Please direct all correspondence regarding this module to: bug-Class-DBI-Plugin-RetrieveAll@rt.cpan.org

COPYRIGHT and LICENSE

Copyright (C) 2004-5 Kasei. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.