|
NAMEMaypole::Model::CDBI::Base - Model base class based on Class::DBIDESCRIPTIONThis 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. add_model_superclassAdds model as superclass to model classes (if necessary)Action MethodsAction methods are methods that are accessed through web (or other public) interface.do_editIf 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.viewThis command shows the object using the view factory template.deleteDeprecated method that calls do_delete or a given classes delete method, please use do_delete insteaddo_deleteUnsuprisingly, this command causes a database record to be forever lost.This method replaces the, now deprecated, delete method provided in prior versions searchDeprecated searching method - use do_search instead.do_searchThis action method searches for database records, it replaces the, now deprecated, search method previously provided.listThe "list" method fills "$r->objects" with all of the objects in the class. The results are paged using a pager.Helper MethodsadoptThis class method is passed the name of a model class that represents a table and allows the master model class to do any set-up required.relatedThis method returns a list of has-many accessors. A brewery has many beers, so "BeerDB::Brewery" needs to return "beers".related_classGiven an accessor name as a method, this function returns the class this accessor returns.search_columns$class->search_columns; Returns a list of columns suitable for searching - used in factory templates, over-ridden in classes. Provides same list as display_columns unless over-ridden. related_meta$class->related_meta($col); Returns the hash ref of relationship meta info for a given column. stringify_columnReturns the name of the column to use when stringifying and object. do_pagerSets 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. orderReturns 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. fetch_objectsReturns 1 or more objects of the given class when provided with the request_isa_classPrivate method to return the class a column belongs to that was inherited by an is_a relationship. This should probably be public but need to think of APIcolumn_typemy $type = $class->column_type('column_name'); This returns the 'type' of this column (VARCHAR(20), BIGINT, etc.) For now, it returns "BOOL" for tinyints. TODO :: TEST with enums required_columnsAccessor to get/set required columns for forms, validation, etc. Returns list of required columns. Accepts an array ref of column names. $class->required_columns([qw/foo bar baz/]); Allows you to specify the required columns for a class, over-riding any assumptions and guesses made by Maypole. Any columns specified as required will no longer be 'nullable' or optional, and any columns not specified as 'required' will be 'nullable' or optional. The default for a column is nullable, or whatever is discovered from database schema. Use this instead of $config->{$table}{required_cols} Note : you need to setup the model class before calling this method. column_requiredReturns true if a column is required my $required = $class->column_required($column_name); Columns can be required by the application but not the database, but not the other way around, hence there is also a column_nullable method which will tell you if the column is nullable within the database itself. column_nullableReturns true if a column can be NULL within the underlying database and false if not. my $nullable = $class->column_nullable($column_name); Any columns that are not nullable will automatically be specified as required, you can also specify nullable columns as required within your application. It is recomended you use column_required rather than column_nullable within your application, this method is more useful if extending the model or handling your own validation. column_defaultReturns default value for column or the empty string. Columns with NULL, CURRENT_TIMESTAMP, or Zeros( 0000-00...) for dates and times have '' returned.get_classmetadataGets class meta data *excluding cgi input* for the passed in class or the calling class. *NOTE* excludes cgi inputs. This method is handy to call from templates when you need some metadata for a related class.SEE ALSOMaypole, Maypole::Model::Base.AUTHORMaypole is currently maintained by Aaron Trevena.AUTHOR EMERITUSSimon Cozens, "simon#cpan.org"Simon Flack maintained Maypole from 2.05 to 2.09 Sebastian Riedel, "sri#oook.de" maintained Maypole from 1.99_01 to 2.04 LICENSEYou may distribute this code under the same terms as Perl itself.
Visit the GSP FreeBSD Man Page Interface. |