[Bast-commits] r3495 - in branches/DBIx-Class-current: . lib/DBIx/Class

matthewt at dev.catalyst.perl.org matthewt at dev.catalyst.perl.org
Wed Jun 13 02:18:01 GMT 2007


Author: matthewt
Date: 2007-06-13 02:18:01 +0100 (Wed, 13 Jun 2007)
New Revision: 3495

Modified:
   branches/DBIx-Class-current/Changes
   branches/DBIx-Class-current/lib/DBIx/Class/Row.pm
Log:
make last_insert_id take multiple column names

Modified: branches/DBIx-Class-current/Changes
===================================================================
--- branches/DBIx-Class-current/Changes	2007-06-12 22:42:11 UTC (rev 3494)
+++ branches/DBIx-Class-current/Changes	2007-06-13 01:18:01 UTC (rev 3495)
@@ -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

Modified: branches/DBIx-Class-current/lib/DBIx/Class/Row.pm
===================================================================
--- branches/DBIx-Class-current/lib/DBIx/Class/Row.pm	2007-06-12 22:42:11 UTC (rev 3494)
+++ branches/DBIx-Class-current/lib/DBIx/Class/Row.pm	2007-06-13 01:18:01 UTC (rev 3495)
@@ -165,18 +165,22 @@
   $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, at 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})




More information about the Bast-commits mailing list