OK, sequences finally working.
[dbsrgits/DBIx-Class-ResultSource-MultipleTableInheritance.git] / lib / DBIx / Class / ResultSource / MultipleTableInheritance.pm
index 805f843..5a8fd88 100644 (file)
@@ -4,7 +4,6 @@ use strict;
 use warnings;
 use parent qw(DBIx::Class::ResultSource::View);
 use Method::Signatures::Simple;
-use Carp::Always;
 use Carp::Clan qw/^DBIx::Class/;
 use aliased 'DBIx::Class::ResultSource::Table';
 use aliased 'DBIx::Class::ResultClass::HashRefInflator';
@@ -370,8 +369,23 @@ method view_definition () {
   push(@all_parents, $super_view) if defined($super_view);
   my @sources = ($table, @all_parents);
   my @body_cols = map body_cols($_), @sources;
+
+  # Order body_cols to match the columns order.
+  # Must match or you get typecast errors.
+  my %body_cols = map { $_->{name} => $_ } @body_cols;
+  @body_cols =
+    map { $body_cols{$_} }
+    grep { defined $body_cols{$_} }
+    $self->columns;
   my @pk_cols = pk_cols $self;
 
+  # Grab sequence from root table. Only works with one PK named id...
+  # TBD: fix this so it's more flexible.
+  for my $pk_col (@pk_cols) {
+    $self->columns_info->{ $pk_col->{name} }->{sequence} =
+      $self->root_table->name . '_id_seq';
+  }
+
   # SELECT statement
 
   my $am_root = !($super_view || @other_parents);