use base 'DBIx::Class'; __PACKAGE__->load_components("Core"); __PACKAGE__->table("Locations"); __PACKAGE__->add_columns( "locationid", { data_type => "integer", is_nullable => 0, size => undef }, "name", { data_type => "string", is_nullable => 0, size => undef }, ); __PACKAGE__->set_primary_key("locationid"); __PACKAGE__->has_many( "npcs", "fhl::Schema::Npcs", { "foreign.locationid" => "self.locationid" }, ); __PACKAGE__->has_many( "incidents", "fhl::Schema::Incidents", { "foreign.locationid" => "self.locationid" }, ); ... my $source = __PACKAGE__->result_source_instance(); my $new_source = $source->new($source); $new_source->source_name( 'DB::Locations::NumberActiveIncidents' ); $new_source->name( \< ? GROUP BY l.locationid ORDER BY NumIncidents DESC ) SQL fhl::Schema->register_source( 'DB::Locations::NumberActiveIncidents' => $new_source );