From: Tomas Doran Date: Tue, 9 Aug 2011 09:08:23 +0000 (+0000) Subject: Fix SYNOPSIS - RT#70156 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0b751b444ab2557da809d25100452dd666753f1a;p=dbsrgits%2FDBIx-Class-UserStamp.git Fix SYNOPSIS - RT#70156 git-svn-id: http://dev.catalyst.perl.org/repos/bast/DBIx-Class-UserStamp/1.000/trunk@9907 bd8105ee-0ff8-0310-8827-fb3f25b6796d --- diff --git a/Changes b/Changes index c4e0bdc..c26bb2f 100644 --- a/Changes +++ b/Changes @@ -1,4 +1,6 @@ - Add repository metadata RT#70156 + - Fix SYNOPSIS to note that $schema->clone + needs to be called. RT#70156 0.11 2008-08-26 - Port to DBIx::Class::DynamicDefault diff --git a/lib/DBIx/Class/UserStamp.pm b/lib/DBIx/Class/UserStamp.pm index dd2a1ca..183c36c 100644 --- a/lib/DBIx/Class/UserStamp.pm +++ b/lib/DBIx/Class/UserStamp.pm @@ -29,22 +29,27 @@ added or updated. 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 }, @@ -53,9 +58,9 @@ added or updated. ); 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