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() ) { $result_source = MySchema->resultset($reps_source_name); } if (!$result_source) { my $inner_sql_select; my $inner_sql_where; my $inner_sql_group_by; # some gubbins that creates the SQL fields based on: $from and $to my $inner_sql = <<"SQL"; ( SELECT * FROM ( SELECT $inner_sql_select FROM domain WHERE ( $inner_sql_where ) GROUP BY $inner_sql_group_by ORDER BY $inner_sql_group_by ) rep NATURAL JOIN domain ) SQL $result_source->name( \$inner_sql ); MySchema->register_source( $result_source_name => $result_source ); } return MySchema->resultset( $result_source_name ); } When I run Catalyst I can see that I now get a bunch of new classes in MyApp::Model (as expected) [debug] Loaded components: .-----------------------------------------------------------------+----------. | Class | Type | +-----------------------------------------------------------------+----------+ | MyApp::Model::MySchema::ResultSetFrom1To2 | class | | MyApp::Model::MySchema::ResultSetFrom1To3 | class | And if I access this new resultset directly then everything works as expected: @entries = MyApp->model("MySchema::ResultSetFrom1To2")->search({}, { bind => [EMAIL PROTECTED] }); However, I would prefer to access the resultset via the same method that I'm creating them from rather than having to know what these resultsets happen to be called under the hood or worry about typos - i.e. use the method MySchema::Domain::get_custom_resultset($from, $to) However, I can't get this to work as expected - the following code gives me the error: undef error - Can't call method "select" on an undefined value at /opt/perl-5.8.8/lib/site_perl/5.8.8/DBIx/Class/ResultSet.pm line 514. --- package MySchema::Domain::ResultSet; use base qw( DBIx::Class::ResultSet ); sub get_results_from_x_to_y { my ($from, $to); my $resultset = MySchema::Domain::get_custom_resultset($from, $to); my @bind_values = ($from, $to); # more complicated than this in reality return $resultset->search( {}, { bind => @bind_values } ); } Is this something to do with setting the __PACKAGE__->resultset_class (if so, I'll take it to the dbi-class list)? Side question - should I expect the 'catalysed' schema to behave exactly the same as the non-catalysed schema? Appreciate any help at all - cheers, Ian
_______________________________________________ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/