From: Matt S Trout Date: Wed, 13 Jun 2007 01:18:01 +0000 (+0000) Subject: make last_insert_id take multiple column names X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3fda409f9ae306c3d815c04ff1aab48335474af0;p=dbsrgits%2FDBIx-Class-Historic.git make last_insert_id take multiple column names --- diff --git a/Changes b/Changes index cc499e8..baee415 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for DBIx::Class + - tweaked Row.pm to make last_insert_id take multiple column names - added stacktrace option to Schema, makes throw_exception use "confess" - make database handles use throw_exception by default diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index 40e7ffa..3dad52d 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -165,18 +165,22 @@ sub insert { $source->storage->insert($source, { $self->get_columns }); ## PK::Auto - my ($pri, $too_many) = grep { !defined $self->get_column($_) || - ref($self->get_column($_)) eq 'SCALAR'} $self->primary_columns; - if(defined $pri) { - $self->throw_exception( "More than one possible key found for auto-inc on ".ref $self ) - if defined $too_many; + my @auto_pri = grep { + !defined $self->get_column($_) || + ref($self->get_column($_)) eq 'SCALAR' + } $self->primary_columns; + + if (@auto_pri) { + #$self->throw_exception( "More than one possible key found for auto-inc on ".ref $self ) + # if defined $too_many; my $storage = $self->result_source->storage; $self->throw_exception( "Missing primary key but Storage doesn't support last_insert_id" ) unless $storage->can('last_insert_id'); - my $id = $storage->last_insert_id($self->result_source,$pri); - $self->throw_exception( "Can't get last insert id" ) unless $id; - $self->store_column($pri => $id); + my @ids = $storage->last_insert_id($self->result_source,@auto_pri); + $self->throw_exception( "Can't get last insert id" ) + unless (@ids == @auto_pri); + $self->store_column($auto_pri[$_] => $ids[$_]) for 0 .. $#ids; } if(!$self->{_rel_in_storage})