1Maypole::Model::CDBI(3)User Contributed Perl DocumentatioMnaypole::Model::CDBI(3)
2
3
4

NAME

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

DESCRIPTION

9       This is a master model class which uses Class::DBI to do all the hard
10       work of fetching rows and representing them as objects. It is a good
11       model to copy if you're replacing it with other database abstraction
12       modules.
13
14       It implements a base set of methods required for a Maypole Data Model.
15
16       It inherits accessor and helper methods from Maypole::Model::Base.
17
18       When specified as the application model, it will use Class::DBI::Loader
19       to generate the model classes from the provided database. If you do not
20       wish to use this functionality, use Maypole::Model::CDBI::Plain which
21       will instead use Class::DBI classes provided.
22
23       Untainter
24
25       Set the class you use to untaint and validate form data Note it must be
26       of type CGI::Untaint::Maypole (takes $r arg) or CGI::Untaint
27

Action Methods

29       Action methods are methods that are accessed through web (or other pub‐
30       lic) interface.
31
32       do_edit
33
34       If there is an object in "$r->objects", then it should be edited with
35       the parameters in "$r->params"; otherwise, a new object should be cre‐
36       ated with those parameters, and put back into "$r->objects".  The tem‐
37       plate should be changed to "view", or "edit" if there were any errors.
38       A hash of errors will be passed to the template.
39
40       delete
41
42       Deprecated method that calls do_delete or a given classes delete
43       method, please use do_delete instead
44
45       do_delete
46
47       Unsuprisingly, this command causes a database record to be forever
48       lost.
49
50       This method replaces the, now deprecated, delete method provided in
51       prior versions
52
53       search
54
55       Deprecated searching method - use do_search instead.
56
57       do_search
58
59       This action method searches for database records, it replaces the, now
60       deprecated, search method previously provided.
61
62       list
63
64       The "list" method fills "$r->objects" with all of the objects in the
65       class. The results are paged using a pager.
66

Helper Methods

68       adopt
69
70       This class method is passed the name of a model class that represensts
71       a table and allows the master model class to do any set-up required.
72
73       related
74
75       This method returns a list of has-many accessors. A brewery has many
76       beers, so "BeerDB::Brewery" needs to return "beers".
77
78       related_class
79
80       Given an accessor name as a method, this function returns the class
81       this accessor returns.
82
83       related_meta
84
85         $class->related_meta($col);
86
87       Returns the hash ref of relationship meta info for a given column.
88
89       stringify_column
90
91          Returns the name of the column to use when stringifying
92          and object.
93
94       do_pager
95
96          Sets the pager template argument ($r->{template_args}{pager})
97          to a Class::DBI::Pager object based on the rows_per_page
98          value set in the configuration of the application.
99
100          This pager is used via the pager macro in TT Templates, and
101          is also accessible via Mason.
102
103       order
104
105           Returns the SQL order syntax based on the order parameter passed
106           to the request, and the valid columns.. i.e. 'title ASC' or 'date_created DESC'.
107
108           $sql .= $self->order($r);
109
110           If the order column is not a column of this table,
111           or an order argument is not passed, then the return value is undefined.
112
113           Note: the returned value does not start with a space.
114
115       setup
116
117         This method is inherited from Maypole::Model::Base and calls setup_database,
118         which uses Class::DBI::Loader to create and load Class::DBI classes from
119         the given database schema.
120
121       setup_database
122
123       The $opts argument is a hashref of options.  The "options" key is a
124       hashref of Database connection options . Other keys may be various
125       Loader arguments or flags.  It has this form:
126        {
127          # DB connection options
128          options { AutoCommit => 1 , ... },
129          # Loader args
130          relationships => 1,
131          ...
132        }
133
134       class_of
135
136         returns class for given table
137
138       fetch_objects
139
140       Returns 1 or more objects of the given class when provided with the
141       request
142
143       _isa_class
144
145       Private method to return the class a column belongs to that was inher‐
146       ited by an is_a relationship.  This should probably be public but need
147       to think of API
148
149       column_type
150
151           my $type = $class->column_type('column_name');
152
153       This returns the 'type' of this column (VARCHAR(20), BIGINT, etc.)  For
154       now, it returns "BOOL" for tinyints.
155
156       TODO :: TEST with enums
157
158       required_columns
159
160         Accessor to get/set required columns for forms, validation, etc.
161
162         Returns list of required columns. Accepts an array ref of column names.
163
164         $class->required_columns([qw/foo bar baz/]);
165
166         Allows you to specify the required columns for a class, over-riding any
167         assumptions and guesses made by Maypole.
168
169         Use this instead of $config->{$table}{required_cols}
170
171         Note : you need to setup the model class before calling this method.
172
173       column_required
174
175         Returns true if a column is required
176
177         my $required = $class->column_required($column_name);
178
179         Columns can be required by the application but not the database, but not the other way around,
180         hence there is also a column_nullable method which will tell you if the column is nullable
181         within the database itself.
182
183       column_nullable
184
185         Returns true if a column can be NULL within the underlying database and false if not.
186
187         my $nullable = $class->column_nullable($column_name);
188
189         Any columns that are not nullable will automatically be specified as required, you can
190         also specify nullable columns as required within your application.
191
192         It is recomended you use column_required rather than column_nullable within your
193         application, this method is more useful if extending the model or handling your own
194         validation.
195
196       column_default
197
198       Returns default value for column or the empty string.  Columns with
199       NULL, CURRENT_TIMESTAMP, or Zeros( 0000-00...) for dates and times have
200       '' returned.
201
202       get_classmetadata
203
204       Gets class meta data *excluding cgi input* for the passed in class or
205       the calling class. *NOTE* excludes cgi inputs. This method is handy to
206       call from templates when you need some metadata for a related class.
207
208
209
210perl v5.8.8                       2005-11-23           Maypole::Model::CDBI(3)
Impressum