s/primary_columns/_pri_cols/ for Firebird
[dbsrgits/DBIx-Class-Historic.git] / lib / DBIx / Class / Row.pm
index f36eba0..bace837 100644 (file)
@@ -347,6 +347,26 @@ sub insert {
     $self->store_column($auto_pri[$_] => $ids[$_]) for 0 .. $#ids;
   }
 
+  # get non-PK auto-incs
+  {
+    my $rsrc = $self->result_source;
+    my %pk;
+    @pk{ $rsrc->primary_columns } = (); 
+
+    my @non_pk_autoincs = grep {
+      (not exists $pk{$_})
+      && (not defined $self->get_column($_))
+      && $rsrc->column_info($_)->{is_auto_increment}
+    } $rsrc->columns;
+
+    if (@non_pk_autoincs) {
+      my @ids = $rsrc->storage->last_insert_id($rsrc, @non_pk_autoincs);
+
+      if (@ids == @non_pk_autoincs) {
+        $self->store_column($non_pk_autoincs[$_] => $ids[$_]) for 0 .. $#ids;
+      }
+    }
+  }
 
   $self->{_dirty_columns} = {};
   $self->{related_resultsets} = {};
@@ -450,7 +470,7 @@ need to preserve the hashref, it is sufficient to pass a shallow copy
 to C<update>, e.g. ( { %{ $href } } )
 
 If the values passed or any of the column values set on the object
-contain scalar references, eg:
+contain scalar references, e.g.:
 
   $row->last_modified(\'NOW()');
   # OR
@@ -952,7 +972,7 @@ so that the database can insert its own autoincremented values into
 the new object.
 
 Relationships will be followed by the copy procedure B<only> if the
-relationship specifes a true value for its
+relationship specifies a true value for its
 L<cascade_copy|DBIx::Class::Relationship::Base> attribute. C<cascade_copy>
 is set by default on C<has_many> relationships and unset on all others.
 
@@ -975,7 +995,7 @@ sub copy {
   $new->insert;
 
   # Its possible we'll have 2 relations to the same Source. We need to make
-  # sure we don't try to insert the same row twice esle we'll violate unique
+  # sure we don't try to insert the same row twice else we'll violate unique
   # constraints
   my $rels_copied = {};