Skip Menu |

This queue is for tickets about the Catalyst-Model-DBIC-Schema CPAN distribution.

Report information
The Basics
Id: 88366
Status: new
Priority: 0/
Queue: Catalyst-Model-DBIC-Schema

People
Owner: Nobody in particular
Requestors: mods [...] hank.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



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;
Subject: Feature request -- use default schema class names
See this discussion: http://lists.scsys.co.uk/pipermail/catalyst/2013-February/029284.html Catalyst::Model::DBIC::Schema creates result classes in a namespace associated with the app instead of the DBIC result class names. This becomes a problem when these objects are cached and shared between *different* applications. If I cache an "MyApp::Result::Foo" object but then "OtherApp" reads that cache it has no idea what "MyApp" is. But, if they use the original DBIC class names all is well. So, I hacked in a very small patch so I could control this via configuration. See any problem with adding this? If not I can provide a better patch and docs. Index: lib/Catalyst/Model/DBIC/Schema.pm =================================================================== --- lib/Catalyst/Model/DBIC/Schema.pm (revision 2279) +++ lib/Catalyst/Model/DBIC/Schema.pm (revision 2280) @@ -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;