[Dbix-class] Use of ->resultset mandatory?
Dan Horne
dan.horne at redbone.co.nz
Mon Oct 30 22:01:51 GMT 2006
> From: Steven Mackenzie
> Sent: Tuesday, 31 October 2006 10:04 a.m.
> Why is there no accessor in the schema class for each table?
> Wouldn't it be obvious to type $schema->MyTableClass->search( .. )
>
Yeah, I agree. Basically when I generate my schema packages the very first
time, I use DBIx::Class::Schema::Loader, after which I maintain the schemas
by hand. That code that calls Loader also generates a simple package that
looks something like this:
package MyApp::DB;
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(rs MyTable MyTable2);
#---------------------------------------------------------------------------
--
# Return the resultset for the supplied table
#---------------------------------------------------------------------------
--
sub rs {
my $self = shift;
my $table_object = shift;
return $self->Schema->resultset($table_object);
}
sub MyTable {
my $self = shift;
return $self->rs('MyTable');
}
sub MyTable2 {
my $self = shift;
return $self->rs('MyTable2');
}
1;
So now I can simply go $self->MyTable->search in my code. I know purists
will bristle at this approach, but it makes my life easier, so damn the
torpedoes
Dan
More information about the Dbix-class
mailing list