1Maypole::Model::CDBI::BUasseer(3C)ontributed Perl DocumeMnatyaptoiloen::Model::CDBI::Base(3)
2
3
4
6 Maypole::Model::CDBI::Base - Model base class based on Class::DBI
7
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 add_model_superclass
19 Adds model as superclass to model classes (if necessary)
20
22 Action methods are methods that are accessed through web (or other
23 public) interface.
24
25 do_edit
26 If there is an object in "$r->objects", then it should be edited with
27 the parameters in "$r->params"; otherwise, a new object should be
28 created with those parameters, and put back into "$r->objects". The
29 template should be changed to "view", or "edit" if there were any
30 errors. A hash of errors will be passed to the template.
31
32 view
33 This command shows the object using the view factory template.
34
35 delete
36 Deprecated method that calls do_delete or a given classes delete
37 method, please use do_delete instead
38
39 do_delete
40 Unsuprisingly, this command causes a database record to be forever
41 lost.
42
43 This method replaces the, now deprecated, delete method provided in
44 prior versions
45
46 search
47 Deprecated searching method - use do_search instead.
48
49 do_search
50 This action method searches for database records, it replaces the, now
51 deprecated, search method previously provided.
52
53 list
54 The "list" method fills "$r->objects" with all of the objects in the
55 class. The results are paged using a pager.
56
58 adopt
59 This class method is passed the name of a model class that represents a
60 table and allows the master model class to do any set-up required.
61
62 related
63 This method returns a list of has-many accessors. A brewery has many
64 beers, so "BeerDB::Brewery" needs to return "beers".
65
66 related_class
67 Given an accessor name as a method, this function returns the class
68 this accessor returns.
69
70 search_columns
71 $class->search_columns;
72
73 Returns a list of columns suitable for searching - used in factory
74 templates, over-ridden in classes. Provides same list as
75 display_columns unless over-ridden.
76
77 related_meta
78 $class->related_meta($col);
79
80 Returns the hash ref of relationship meta info for a given column.
81
82 stringify_column
83 Returns the name of the column to use when stringifying
84 and object.
85
86 do_pager
87 Sets the pager template argument ($r->{template_args}{pager})
88 to a Class::DBI::Pager object based on the rows_per_page
89 value set in the configuration of the application.
90
91 This pager is used via the pager macro in TT Templates, and
92 is also accessible via Mason.
93
94 order
95 Returns the SQL order syntax based on the order parameter passed
96 to the request, and the valid columns.. i.e. 'title ASC' or 'date_created DESC'.
97
98 $sql .= $self->order($r);
99
100 If the order column is not a column of this table,
101 or an order argument is not passed, then the return value is undefined.
102
103 Note: the returned value does not start with a space.
104
105 fetch_objects
106 Returns 1 or more objects of the given class when provided with the
107 request
108
109 _isa_class
110 Private method to return the class a column belongs to that was
111 inherited by an is_a relationship. This should probably be public but
112 need to think of API
113
114 column_type
115 my $type = $class->column_type('column_name');
116
117 This returns the 'type' of this column (VARCHAR(20), BIGINT, etc.) For
118 now, it returns "BOOL" for tinyints.
119
120 TODO :: TEST with enums
121
122 required_columns
123 Accessor to get/set required columns for forms, validation, etc.
124
125 Returns list of required columns. Accepts an array ref of column names.
126
127 $class->required_columns([qw/foo bar baz/]);
128
129 Allows you to specify the required columns for a class, over-riding any
130 assumptions and guesses made by Maypole.
131
132 Any columns specified as required will no longer be 'nullable' or optional, and
133 any columns not specified as 'required' will be 'nullable' or optional.
134
135 The default for a column is nullable, or whatever is discovered from database
136 schema.
137
138 Use this instead of $config->{$table}{required_cols}
139
140 Note : you need to setup the model class before calling this method.
141
142 column_required
143 Returns true if a column is required
144
145 my $required = $class->column_required($column_name);
146
147 Columns can be required by the application but not the database, but not the other way around,
148 hence there is also a column_nullable method which will tell you if the column is nullable
149 within the database itself.
150
151 column_nullable
152 Returns true if a column can be NULL within the underlying database and false if not.
153
154 my $nullable = $class->column_nullable($column_name);
155
156 Any columns that are not nullable will automatically be specified as required, you can
157 also specify nullable columns as required within your application.
158
159 It is recomended you use column_required rather than column_nullable within your
160 application, this method is more useful if extending the model or handling your own
161 validation.
162
163 column_default
164 Returns default value for column or the empty string. Columns with
165 NULL, CURRENT_TIMESTAMP, or Zeros( 0000-00...) for dates and times have
166 '' returned.
167
168 get_classmetadata
169 Gets class meta data *excluding cgi input* for the passed in class or
170 the calling class. *NOTE* excludes cgi inputs. This method is handy to
171 call from templates when you need some metadata for a related class.
172
174 Maypole, Maypole::Model::Base.
175
177 Maypole is currently maintained by Aaron Trevena.
178
180 Simon Cozens, "simon#cpan.org"
181
182 Simon Flack maintained Maypole from 2.05 to 2.09
183
184 Sebastian Riedel, "sri#oook.de" maintained Maypole from 1.99_01 to 2.04
185
187 You may distribute this code under the same terms as Perl itself.
188
189
190
191perl v5.28.1 2007-08-03 Maypole::Model::CDBI::Base(3)