NAME

Maypole::Model::CDBI - Model class based on Class::DBI

DESCRIPTION

This is a master model class which uses Class::DBI to do all the hard work of fetching rows and representing them as objects. It is a good model to copy if you're replacing it with other database abstraction modules.

It implements a base set of methods required for a Maypole Data Model.

It inherits accessor and helper methods from Maypole::Model::Base.

When specified as the application model, it will use Class::DBI::Loader to generate the model classes from the provided database. If you do not wish to use this functionality, use Maypole::Model::CDBI::Plain which will instead use Class::DBI classes provided.

Action Methods

Action methods are methods that are accessed through web (or other public) interface.

do_edit

If there is an object in $r->objects, then it should be edited with the parameters in $r->params; otherwise, a new object should be created with those parameters, and put back into $r->objects. The template should be changed to view, or edit if there were any errors. A hash of errors will be passed to the template.

delete

Deprecated method that calls do_delete or a given classes delete method, please use do_delete instead

do_delete

Unsuprisingly, this command causes a database record to be forever lost.

This method replaces the, now deprecated, delete method provided in prior versions

Deprecated searching method - use do_search instead.

This action method searches for database records, it replaces the, now deprecated, search method previously provided.

list

The list method fills $r->objects with all of the objects in the class. The results are paged using a pager.

Helper Methods

adopt

This class method is passed the name of a model class that represensts a table and allows the master model class to do any set-up required.

is_class

Tell if action is a class method (See Maypole::Plugin::Menu)

is_object

Tell if action is a object method (See Maypole::Plugin::Menu)

This method returns a list of has-many accessors. A brewery has many beers, so BeerDB::Brewery needs to return beers.

Given an accessor name as a method, this function returns the class this accessor returns.

  $class->related_meta($col);

Given a column associated with a relationship it will return the relatation ship type and the meta info for the relationship on the column.

isa_class

Returns class of a column inherited by is_a.

accessor_classes

Returns hash ref of classes for accessors.

This is an attempt at a more efficient method than calling "related_class()" a bunch of times when you need it for many relations. It may be good to call at startup and store in a global config.

stringify_column

   Returns the name of the column to use when stringifying
   and object.

do_pager

   Sets the pager template argument ($r->{template_args}{pager})
   to a Class::DBI::Pager object based on the rows_per_page
   value set in the configuration of the application.

   This pager is used via the pager macro in TT Templates, and
   is also accessible via Mason.

order

    Returns the SQL order syntax based on the order parameter passed
    to the request, and the valid columns.. i.e. 'title ASC' or 'date_created DESC'.

    $sql .= $self->order($r);

    If the order column is not a column of this table,
    or an order argument is not passed, then the return value is undefined.

    Note: the returned value does not start with a space.

setup

  This method is inherited from Maypole::Model::Base and calls setup_database,
  which uses Class::DBI::Loader to create and load Class::DBI classes from
  the given database schema.

setup_database

The $opts argument is a hashref of options. The "options" key is a hashref of Database connection options . Other keys may be various Loader arguments or flags. It has this form: { # DB connection options options { AutoCommit => 1 , ... }, # Loader args relationships => 1, ... }

class_of

  returns class for given table

fetch_objects

Returns 1 or more objects of the given class when provided with the request