GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  GANTRY::UTILS::DBIXCLASS (3)

.ds Aq ’

NAME

Gantry::Utils::DBIxClass - a DBIx::Class subclass models can inherit from

CONTENTS

SYNOPSIS



    package YourModel;

    use base Gantry::Utils::DBIxClass;

    # standard DBIx::Class table definition

    __PACKAGE__->sequence_name( your_seq );
    __PACKAGE__->base_model( Your::Schema );



DESCRIPTION

By inheriting from this module instead of from DBIx::Class directly, you gain additional helper methods which various parts of Gantry use.

METHODS

get_listing Parameters: A hash reference with these keys:



    schema   - a DBIx::Class::Schema object
    order_by - [optional] a valid SQL ORDER BY clause



Returns: an array of all rows in your table. The default order is the foreign_display fields.

get_form_selections Parameters: A hash reference with this key:



    schema - a DBIx::Class::Schema object



Returns: A hash keyed by foreign table name storing an array of items. Each item is a hash with two keys like this:



    {
        value => $item->$value_method
        label => $item->foreign_display(),
    }



This is precisely the format that all Gantry CRUD schemes expect in their forms.

The value_method is either id (the default) or the result of calling the optional get_value_method on the relevant foreign table model class.

stringify_self This is an overload callback used when database row objects are in string context. The one here calls id on the row object. Children should override if their primary key is not a single column called ’id’.
create This method is provided for historical reasons and should no longer be used, see gcreate below.
In addition to the above methods, this base class provides the following convenience accessors to save typing. For example, instead of typing:



    my $schema = $self->get_schema();
    my @rows   = $schema->resultset( table_name )->search(
            { ... },
            { ... }
    );



These methods let you say:



    my @rows => $TABLE_NAME->gsearch(
            $self,
            { ... },
            { ... }
    );



gcreate
gsearch
gfind
gfind_or_create
gupdate_or_create
For these methods to work, the invoking controller must use Gantry::Plugins::DBIxClassConn. It handles dbic connections and exports get_schema which all of the g methods call.

Alternatively, if you are in a script, you may use other similar methods:



    my $schema = AddressBook::Model->connect(
        $conf->{ dbconn },
        $conf->{ dbuser },
        $conf->{ dbpass },
    );

    my @rows => $TABLE_NAME->ssearch( $schema, ... );



These methods expect a valid dbic schema as their first argument. The available s* methods are:
screate
ssearch
sfind
sfind_or_create
supdate_or_create
Other helper methods:
datetime_now returns the right SQL command for NOW() (datetime field) depending on whether sqlite or mysql or pgsql are used.

For example in controller to set the ’modified’ column:



  $params->{modified} = $MY_MODEL->datetime_now($self);



where $self is $gantry_site object.

AUTHOR

Phil Crow <philcrow2000@yahoo.com>

COPYRIGHT and LICENSE

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.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 GANTRY::UTILS::DBIXCLASS (3) 2016-04-03

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.