> 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
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/