Catalyst::Model::DBIC::Schema::PerRequest - Per request clone of a DBIC model with additional parameters
version 0.002002
package MyApp::Model::RestrictedDB;
use Moose;
extends 'Catalyst::Model::DBIC::Schema::PerRequest';
__PACKAGE__->config(target_model => 'DB');
sub per_request_schema_attributes {
my ($self, $c) = @_;
return (restricting_object => $c->user->obj);
}
In your controller:
$c->model('RestrictedDB')->resultset('...');
Allows you to get a clone of an existing Catalyst::Model::DBIC::Schema model with additional parameters passed to the DBIx::Class::Schema clone.
The name of the original model class.
or
has '+target_model' => (
default => 'DB',
schema_class => 'MyApp::Schema',
);
The name of your DBIx::Class schema.
This method is called automatically and will clone your schema with attributes coming from per_request_schema_attributes. You can override this method directly to return a schema you want, but it's probably better to override per_request_schema_attributes
.
Override this method in your child class and return whatever parameters you need for new schema instance.
sub per_request_schema_attributes {
my ($self, $c, $original_model) = @_;
return (restricting_object => $c->user->obj);
}
Thanks to mst (Matt S. Trout) for the idea and mentorship during the development.
Roman F. <romanf@cpan.org>
This software is copyright (c) 2015 by Roman F..
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.