[Catalyst] How do I access 'Catalysed' custom datasets?

Matt S Trout dbix-class at trout.me.uk
Sun Apr 6 18:04:52 BST 2008

On Tue, Mar 18, 2008 at 07:40:45PM +0000, Ian Sillitoe wrote:
> This may be more of a DBIx::Class issue - if so, apologies - however I think
> it come down to my lack of understanding of exactly what Catalyst is doing
> when it loads DBIx::Class modules hence why I've posted this problem to the
> catalyst mailing list.
> I need to do some sub-selects in DBIx::Class so I've written a function that
> returns a custom resultset depending on some variables - if the resultset
> hasn't already been created then it creates and registers this resultset
> before returning it (based on DBIx::Class::Manual::Cookbook - "Arbitrary SQL
> through a custom ResultSource").
> package MySchema::Domain;
> use base 'DBIx::Class';
> # I'm using a 'static' custom resultset in addition to the 'dynamic' ones
> __PACKAGE__->resultset_class('MySchema::Domain::ResultSet');
> __PACKAGE__->load_components("Core");
> __PACKAGE__->table("domain");
> __PACKAGE__->add_columns();
> sub get_custom_resultset {
>   my ($from, $to) = @_;
>   my $result_source_name = "ResultSetFrom${from}To${to}";
>   my $result_source;
>   # check if we haven't already made this
>   if ( grep { $reps_source_name eq $_ } MySchema->sources() ) {

Don't do that. -always- get a schema passed to you, rather than hard coding
a class. Also, never write class methods in DBIC. If you want methods, add
methods - on row objects for single-record methods, on resultsets for
collection methods, and on the schema for global things.

      Matt S Trout       Need help with your Catalyst or DBIx::Class project?
   Technical Director                    http://www.shadowcat.co.uk/catalyst/
 Shadowcat Systems Ltd.  Want a managed development or deployment platform?
http://chainsawblues.vox.com/            http://www.shadowcat.co.uk/servers/

More information about the Catalyst mailing list