Skip to content

Instantly share code, notes, and snippets.

@moltar
Created November 7, 2012 02:42
Show Gist options
  • Save moltar/4029297 to your computer and use it in GitHub Desktop.
Save moltar/4029297 to your computer and use it in GitHub Desktop.
model
package SW::Web::Model::DB;
use Moose;
extends 'Catalyst::Model::DBIC::Schema';
use SW::Schema::RestrictingObject;
## CatalystX::Component::Traits
# has '+_trait_merge' => (default => 1);
__PACKAGE__->config({
## Catalyst::TraitFor::Model::DBIC::Schema::PerRequestSchema
traits => ['PerRequestSchema'],
schema_class => 'SW::Schema',
});
sub per_request_schema_attributes {
my ($self, $c) = @_;
my %params;
if ($c->user_exists) {
$params{user} = $c->user->get_object;
}
if (defined $c->stash->{company}) {
$params{company} = $c->stash->{company};
}
if (%params) {
return (
restricting_object => SW::Schema::RestrictingObject->new(%params)
);
} else {
return ();
}
}
=head1 NAME
SW::Web::Model::DB - Catalyst DBIC Schema Model
=head1 SYNOPSIS
...
=head1 DESCRIPTION
L<Catalyst::Model::DBIC::Schema> Model using schema L<SW::Schema>
=cut
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment