allow for multipk
[dbsrgits/DBIx-Class-Journal.git] / lib / DBIx / Class / Schema / Journal.pm
index d8da1f7..29aaefc 100644 (file)
@@ -39,7 +39,7 @@ sub _journal_schema_prototype {
 
 
     my $comp = $self->journal_component || "Journal";
-    
+
     my $prefix = $self->journal_prefix || '';
     foreach my $audit (qw(ChangeSet ChangeLog)) {
         my $class = blessed($proto) . "::$audit";
@@ -104,14 +104,6 @@ sub connection {
     return $schema;
 }
 
-sub deploy {
-    my $self = shift;
-
-    $self->next::method(@_);
-
-    $self->journal_schema_deploy(@_);
-}
-
 sub journal_schema_deploy {
     my $self = shift;
 
@@ -138,7 +130,7 @@ sub create_journal_for {
     }
 }
 
-# XXX FIXME deploy is not idempotenta :-(
+# XXX FIXME deploy is not idempotent :-(
 sub bootstrap_journal {
     my $self = shift;
     $self->journal_schema_deploy;
@@ -168,7 +160,7 @@ sub prepopulate_journal {
             next unless $j_sources{$s_name};
 
             my $from_rs = $schema->resultset($s_name);
-            my ($pk) = $from_rs->result_source->primary_columns;
+            my @pks = $from_rs->result_source->primary_columns;
             $from_rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
 
             my $to_rs  = $j_schema->resultset("${s_name}AuditHistory");
@@ -182,15 +174,21 @@ sub prepopulate_journal {
                 })
             ) {
                 # get some number of change log IDs to be generated for this page
-                my @log_ids = map { $_->id }
-                            $changelog_rs->populate([
-                                map {{ changeset_id => $chs_id }} (0 .. $#x)
-                            ]);
-
+                my @log_ids = map $_->id,
+                   $changelog_rs->populate([
+                       map +{ changeset_id => $chs_id }, (0 .. $#x)
+                   ]);
+
+
+                my @datas;
+                for my $idx (0 .. $#x ) {
+                   push @datas, {
+                       create_id => $log_ids[$idx],
+                       map { $_ => $x[$idx]->{$_} } @pks,
+                   }
+                }
                 # create the audit log entries for the rows in this page
-                $log_rs->populate([
-                    map {{ create_id => $log_ids[$_], id => $x[$_]->{$pk} }} (0 .. $#x)
-                ]);
+                $log_rs->populate([@datas]);
 
                 # now populate the audit history
                 $to_rs->populate([