package MyApp::Model::MyAppDB;
use Moose;
+ use namespace::autoclean;
- around 'build_per_context_instance' => sub {
+ extends 'Catalyst::Model::DBIC::Schema';
+ with 'Catalyst::Component::InstancePerContext';
+
+ sub build_per_context_instance {
my ($meth, $self) = (shift, shift);
my ($c) = @_; # There are other params but we dont care about them
my $new = bless({ %$self }, ref($self));
- my $user_info = $c->_user_in_session;
+ my $user_info = $c->_user_in_session;
+ $new->schema($new->schema->clone);
my $user = $new->schema->resultset('User')->new_result({ %$user_info });
$new->schema->current_user_id($user->id) if (defined $user_info);
return $new;
- };
+ }
package MyApp::Schema::SomeTable;
__PACKAGE__->load_components(qw( UserStamp ... Core ));
-
+
__PACKAGE__->add_columns(
id => { data_type => 'integer' },
u_created => { data_type => 'int', store_user_on_create => 1 },
);
Now, any update or create actions will update the specified columns with the
-current user_id, using the current_user_id accessor.
+current user_id, using the current_user_id accessor.
-This is effectively trigger emulation to ease user id field insertion
+This is effectively trigger emulation to ease user id field insertion
=cut