This more of a question and suggested patch than a bug.
I have two Catalyst apps that share the same DBIC schema. There are some very expensive
queries where I cache the result objets of a DBIC query. We want to share these cached items
between apps. The values stored in the cache are DBIC Result/row objects.
The problem is that C::M::D::Schema does this:
$self->composed_schema($schema_class->compose_namespace($class))
unless $is_installed;
I assume the purpose of that code is to have Result objects be blessed into app-specific classes
(instead of the normal Result class). But, that means these row objects cannot be shared across
applications.
My suggestion (and question) is to change that via a configuration to set simply do this:
$self->composed_schema( $schema_class );
which then Result class names are always based on the Schema, not the application.
See why this might cause problems? Look at the attached diff as a possible implementation.
I'm sure there's a better name for the config variable.
Subject: | Schema.diff |
Index: lib/Catalyst/Model/DBIC/Schema.pm
===================================================================
--- lib/Catalyst/Model/DBIC/Schema.pm (revision 2278)
+++ lib/Catalyst/Model/DBIC/Schema.pm (working copy)
@@ -5,7 +5,7 @@
extends 'Catalyst::Model';
with 'CatalystX::Component::Traits';
-our $VERSION = '0.60';
+our $VERSION = '0.61';
$VERSION = eval $VERSION;
use namespace::autoclean;
@@ -18,6 +18,7 @@
use MooseX::Types::Moose qw/ArrayRef Str ClassName Undef/;
+
=head1 NAME
Catalyst::Model::DBIC::Schema - DBIx::Class::Schema Model Class
@@ -449,6 +450,10 @@
sub app_class { $app_class }
+has use_standard_result_class => ( is => 'ro', isa => 'Bool', default => 0 );
+
+
sub BUILD {
my ($self, $args) = @_;
my $class = $self->_original_class_name;
@@ -476,9 +481,16 @@
my $is_installed = defined $self->composed_schema;
- $self->composed_schema($schema_class->compose_namespace($class))
- unless $is_installed;
+ $self->composed_schema(
+ $self->use_standard_result_class
+ ? $schema_class
+ : $schema_class->compose_namespace($class)
+ ) unless $is_installed;
+
$self->schema($self->composed_schema->clone)
unless $self->schema;