Gantry::Utils::ModelHelper - mixin for model base classes


    use Gantry::Utils::ModelHelper qw(

    sub get_db_options {
        return {};  # put your default options here
        # consider calling __PACKAGE->_default_attributes


This module provides mixin methods commonly needed by model base classes. Note that you must request the methods you want for the mixin scheme to work. Also note that you can request either db_Main or auth_db_Main, but not both. Whichever one you choose will be exported as db_Main in your package.



This method returns a valid dbh using the scheme described in Gantry::Docs::DBConn. It is compatible with Class::DBI and Gantry::Plugins::DBIxClassConn (the later is a mixin which allows easy access to a DBIx::Schema object for controllers).


This method is exported as db_Main and works with the scheme described in Gantry::Docs::DBConn. It too is compatible with Class::DBI and Gantry::Plugins::DBIxClassConn.

I will repeat, if you ask for this method in your use statement:

    use lib/Gantry/Utils/ModelHelper qw( auth_db_Main ... );

it will come into your namespace as db_Main.


This method gives you a selection list for each foriegn key in your table. The lists come to you as a single hash keyed by the table names of the foreign keys. The values in the hash are ready for use by as options on the field (whose type should be select). Example:

        status => [
            { value => 2, label => 'Billed' },
            { value => 1, label => 'In Progress' },
            { value => 3, label => 'Paid' },
        other_table => [ ... ],

To use this method, your models must implement these class methods:


(Must be implemented by the model on which get_form_selections is called.) Returns a list of the fully qualified package names of the models of this table's foreign keys. Example:

    sub get_foreign_tables {
        return qw(

(Must be implemented by all the models of this table's foreign keys.) Returns an array reference whose elements are the names of the columns which will appear on the screen in the selection list. Example:

    sub get_foreign_display_fields {
        return [ qw( last_name first_name ) ];

Replacement for retrieve_all_for_main_listing.

Returns a list of row objects (one for each row in the table). The ORDER BY clause is either the same as the foreign_display columns or chosen by you. If you want to supply the order do it like this:

    my @rows = $MODEL->get_listing ( { order_by => 'last, first' } );

Note that your order_by will be used AS IS, so it must be a valid SQL ORDER BY clause, but feel free to include DESC or anything else you and SQL like.


DEPRECATED use get_listing instead

Returns a list of row objects (one for each row in the table) in order by their foreign_display columns.


Phil Crow <>


Copyright (c) 2006, Phil Crow

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.6 or, at your option, any later version of Perl 5 you may have available.