From: Amiri Barksdale at Home Date: Wed, 4 May 2011 02:53:22 +0000 (-0700) Subject: OK, sequences finally working. X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=d8c2caa7734a8207ef6d648be3ce485baca338fa;p=dbsrgits%2FDBIx-Class-ResultSource-MultipleTableInheritance.git OK, sequences finally working. --- diff --git a/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm b/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm index 805f843..5a8fd88 100644 --- a/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm +++ b/lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm @@ -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); diff --git a/t/04no_sequence_defined.t b/t/04no_sequence_defined.t index dedb510..4d84dc3 100644 --- a/t/04no_sequence_defined.t +++ b/t/04no_sequence_defined.t @@ -4,9 +4,10 @@ use lib 't/lib'; use Test::More qw(no_plan); use Test::Exception; use NoSequenceSalad; +use Devel::Dwarn; BEGIN { - $ENV{DBIC_TRACE} = 0; + $ENV{DBIC_TRACE} = 0; } my ( $dsn, $user, $pass ) = @ENV{ map {"DBICTEST_PG_${_}"} qw/DSN USER PASS/ }; @@ -18,11 +19,14 @@ EOM my $schema = NoSequenceSalad->connect( $dsn, $user, $pass ); $schema->storage->ensure_connected; +$schema->storage->dbh->{Warn} = 0; $schema->storage->_use_insert_returning(0); my $dir = "t/sql"; # tempdir(CLEANUP => 0); $schema->create_ddl_dir( ['PostgreSQL'], 0.1, $dir ); -$schema->deploy( { add_drop_table => 1, add_drop_view => 1 } ); + +lives_ok { $schema->deploy( { add_drop_table => 1, add_drop_view => 1 } ) } +"I can deploy the schema"; isa_ok( $schema->source('Mesclun'), @@ -34,7 +38,7 @@ my ( $bowl_of_salad, $bowl_of_salad1 ); lives_ok { $bowl_of_salad = $schema->resultset('Mesclun') - ->create( { acidity => 4, spiciness => '10', fresh => 0 } ); + ->create( { acidity => 4, spiciness => '10', fresh => 0, } ); } "I can call a create on a view mesclun"; @@ -44,10 +48,12 @@ lives_ok { "I can do it for the other view, too"; my $sqlt_object = $schema->{sqlt}; + +#diag Dwarn $sqlt_object; is_deeply( [ map { $_->name } $sqlt_object->get_views ], [ qw/ - salad + salad mesclun / ], diff --git a/t/lib/LoadTest/Result/JustATable.pm b/t/lib/LoadTest/Result/JustATable.pm index d05669d..1bf4e54 100644 --- a/t/lib/LoadTest/Result/JustATable.pm +++ b/t/lib/LoadTest/Result/JustATable.pm @@ -12,11 +12,11 @@ __PACKAGE__->add_columns( __PACKAGE__->set_primary_key('id'); -#__PACKAGE__->has_many( - #'bars', - #'LoadTest::Result::Bar', - #{ 'foreign.b' => 'self.id' } -#); +__PACKAGE__->has_many( + 'bars', + 'LoadTest::Result::Bar', + { 'foreign.b' => 'self.id' } +); 1; diff --git a/t/lib/LoadTest/Result/Mixin.pm b/t/lib/LoadTest/Result/Mixin.pm index 10eb205..97f0af9 100644 --- a/t/lib/LoadTest/Result/Mixin.pm +++ b/t/lib/LoadTest/Result/Mixin.pm @@ -11,7 +11,6 @@ __PACKAGE__->add_columns( id => { data_type => 'integer', is_auto_increment => 1, - sequence => 'foo_id_seq' }, words => { data_type => 'text' } ); diff --git a/t/lib/NoSequenceSalad/Result/Mesclun.pm b/t/lib/NoSequenceSalad/Result/Mesclun.pm index 2e83e4c..4898cfb 100644 --- a/t/lib/NoSequenceSalad/Result/Mesclun.pm +++ b/t/lib/NoSequenceSalad/Result/Mesclun.pm @@ -12,6 +12,9 @@ __PACKAGE__->result_source_instance->deploy_depends_on( ["NoSequenceSalad::Result::Salad"] ); __PACKAGE__->result_source_instance->add_additional_parent( NoSequenceSalad::Result::Dressing->result_source_instance ); -__PACKAGE__->add_columns( "spiciness", { data_type => "integer" } ); + +__PACKAGE__->add_columns( + spiciness => { data_type => "integer" }, +); 1; diff --git a/t/lib/NoSequenceSalad/Result/Salad.pm b/t/lib/NoSequenceSalad/Result/Salad.pm index d65c39f..21985c7 100644 --- a/t/lib/NoSequenceSalad/Result/Salad.pm +++ b/t/lib/NoSequenceSalad/Result/Salad.pm @@ -12,7 +12,7 @@ __PACKAGE__->add_columns( "id", { data_type => "integer", is_auto_increment => 1, - #sequence => '_salad_id_seq', + #sequence => '_salad_id_seq', }, "fresh", { data_type => "boolean", },