*names_of = sub (@cols) { map $_->{name}, @cols };
- *function_body = sub ($name, $args, $body_parts) {
+ *functionbody = sub ($name, $args, $body_parts) {
my $arglist = join(
', ',
map "_${\$_->{name}} ${\uc($_->{data_type})}",
# NOTE: this assumes a single PK col called id with a sequence somewhere
# but nothing else -should- so fixing this should make everything work
my $insert_func =
- function_body
+ functionbody
$self->name.'_insert',
\@body_cols,
[
# UPDATE function
my $update_func =
- function_body
+ functionbody
$self->name.'_update',
[ @pk_cols, @body_cols ],
[ map $sqla->update(
# DELETE function
my $delete_func =
- function_body
+ functionbody
$self->name.'_delete',
[ @pk_cols ],
[ map $sqla->delete($_->name, $pk_where), @sources ];
=head1 SYNOPSIS
{
- package MyApp::Schema::Result::Coffee;
+ package Cafe::Result::Coffee;
- __PACKAGE__->table_class(
- 'DBIx::Class::ResultSource::MultipleTableInheritance'
- );
+ use strict;
+ use warnings;
+ use parent 'DBIx::Class::Core';
+ use aliased 'DBIx::Class::ResultSource::MultipleTableInheritance'
+ => 'MTI';
+
+ __PACKAGE__->table_class(MTI);
__PACKAGE__->table('coffee');
__PACKAGE__->add_columns(
- "id",
- {
- data_type => "integer",
- default_value => "nextval('coffee_seq'::regclass)",
- is_auto_increment => 1,
- is_foreign_key => 1,
- is_nullable => 0,
- size => 4,
- },
- "flavor",
- {
- data_type => "text",
- default_value => "good",
- },
+ "id", { data_type => "integer" },
+ "flavor", {
+ data_type => "text",
+ default_value => "good" },
);
__PACKAGE__->set_primary_key("id");
}
{
- package MyApp::Schema::Result::Sumatra;
+ package Cafe::Result::Sumatra;
- use parent 'Coffee';
+ use parent 'Cafe::Result::Coffee';
__PACKAGE__->table('sumatra');
- __PACKAGE__->add_columns(
- "aroma",
- {
- data_type => "text",
- default_value => undef,
- is_nullable => 0,
- },
+ __PACKAGE__->add_columns( "aroma",
+ { data_type => "text" }
);
1;
...
- my $schema = MyApp::Schema->connect($dsn);
-
- my $cup = $schema->resultset('Sumatra')->new;
+ my $schema = Cafe->connect($dsn,$user,$pass);
- print STDERR DwarnS $cup->columns;
+ my $cup = $schema->resultset('Sumatra');
- $VAR1 = 'id';
- $VAR2 = 'flavor';
- $VAR3 = 'aroma';
+ print STDERR Dwarn $cup->result_source->columns;
+ "id"
+ "flavor"
+ "aroma"
+ ..
Inherit from this package and you can make a resultset class from a view, but
that's more than a little bit misleading: the result is B<transparently