use strict;
use warnings;

package Catalyst::TraitFor::Model::DBIC::Schema::SharedDatabaseConnection;
$Catalyst::TraitFor::Model::DBIC::Schema::SharedDatabaseConnection::VERSION = '0.01';
use Moose::Role;

has parent_model => (
    is       => 'ro',
    isa      => 'Str',
    required => 1,
);

has _cloned_parent_model => (
    is      => 'rw',
    default => 0,
);
around ACCEPT_CONTEXT => sub {
    my ( $orig, $self, $app, @rest ) = ( shift, shift, @_ );
    unless ( $self->_cloned_parent_model ) {
        $self->schema->storage(
            $app->model( $self->parent_model )->schema->storage );
        $self->_cloned_parent_model(1);
    }
    $self->$orig( $app, @rest );
};

no Moose::Role;
1;
