Fix view ordering by requiring ddo declaration in result class
Amiri Barksdale at Home [Mon, 3 Jan 2011 22:13:03 +0000 (14:13 -0800)]
lib/DBIx/Class/ResultSource/MultipleTableInheritance.pm
t/02view_def.t
t/03insert.t
t/04no_sequence_defined.t
t/lib/CafeInsertion/Result/Coffee.pm
t/lib/CafeInsertion/Result/Cream.pm [new file with mode: 0644]
t/lib/CafeInsertion/Result/Sumatra.pm
t/lib/LoadTest/Result/Bar.pm
t/lib/LoadTest/Result/JustATable.pm
t/lib/NoSequenceSalad/Result/Mesclun.pm

index ba2ec52..16a90af 100644 (file)
@@ -153,7 +153,7 @@ method attach_additional_sources () {
     $table->add_relationship(
       'parent_'.$add->name, $add->source_name, \%pk_join
     );
-    $self->deploy_depends_on->{$add->result_class} = 1;
+    $self->deploy_depends_on->{$add->result_class} = 1 if $add->isa('DBIx::Class::ResultSource::View');
   }
   $table->add_columns(
     map { ($_ => { %{$self->column_info($_)} }) }
index 4b5d2c9..3017243 100644 (file)
@@ -5,7 +5,6 @@ use File::Temp;
 use Test::More qw(no_plan);
 use Test::Exception;
 use LoadTest;
-use Devel::Dwarn;
 
 BEGIN {
     $ENV{DBIC_TRACE} = 0;
@@ -24,6 +23,7 @@ dies_ok { LoadTest->source('Foo')->view_definition }
 
 my $schema = LoadTest->connect( $dsn, $user, $pass );
 $schema->storage->ensure_connected;
+$schema->storage->dbh->{Warn} = 0;
 
 my $dir = "t/sql";    # tempdir(CLEANUP => 0);
 
index f25270c..2293d75 100644 (file)
@@ -4,6 +4,7 @@ use lib 't/lib';
 use Test::More qw(no_plan);
 use Test::Exception;
 use CafeInsertion;
+use Devel::Dwarn;
 
 BEGIN {
     $ENV{DBIC_TRACE} = 0;
@@ -19,6 +20,7 @@ EOM
 my $schema = CafeInsertion->connect( $dsn, $user, $pass );
 $schema->storage->ensure_connected;
 $schema->storage->_use_insert_returning(0);
+$schema->storage->dbh->{Warn} = 0;
 
 my $dir = "t/sql";    # tempdir(CLEANUP => 0);
 $schema->create_ddl_dir( ['PostgreSQL'], 0.1, $dir );
@@ -33,8 +35,13 @@ isa_ok(
 my ( $drink, $drink1 );
 
 lives_ok {
-    $drink = $schema->resultset('Sumatra')
-        ->create( { sweetness => 4, aroma => 'earthy', flavor => 'great' } );
+    $drink = $schema->resultset('Sumatra')->create(
+        {   sweetness => 4,
+            fat_free  => 1,
+            aroma     => 'earthy',
+            flavor    => 'great'
+        }
+    );
 }
 "I can call a create on a view sumatra";
 
@@ -44,11 +51,10 @@ lives_ok {
 "I can do it for the other view, too";
 
 my $sqlt_object = $schema->{sqlt};
-
 is_deeply(
     [ map { $_->name } $sqlt_object->get_views ],
     [   qw/
-            coffee 
+            coffee
             sumatra
             /
     ],
index 04dc763..dedb510 100644 (file)
@@ -43,3 +43,13 @@ lives_ok {
 }
 "I can do it for the other view, too";
 
+my $sqlt_object = $schema->{sqlt};
+is_deeply(
+    [ map { $_->name } $sqlt_object->get_views ],
+    [   qw/
+            salad 
+            mesclun
+            /
+    ],
+    "SQLT view order triumphantly matches our order."
+);
index 0dc65b0..c3f2e27 100644 (file)
@@ -8,6 +8,7 @@ use aliased 'DBIx::Class::ResultSource::MultipleTableInheritance' => 'MTI';
 
 __PACKAGE__->table_class(MTI);
 __PACKAGE__->table('coffee');
+
 __PACKAGE__->add_columns(
     "id",
     {   data_type         => "integer",
diff --git a/t/lib/CafeInsertion/Result/Cream.pm b/t/lib/CafeInsertion/Result/Cream.pm
new file mode 100644 (file)
index 0000000..93efeb1
--- /dev/null
@@ -0,0 +1,20 @@
+package    # hide from PAUSE
+    CafeInsertion::Result::Cream;
+
+use strict;
+use warnings;
+use parent 'DBIx::Class::Core';
+
+__PACKAGE__->table('cream');
+
+__PACKAGE__->add_columns(
+    id => {
+        data_type         => 'integer',
+        is_auto_increment => 1,
+    },
+    fat_free => { data_type => 'boolean', default => 0 }
+);
+
+__PACKAGE__->set_primary_key('id');
+
+1;
index 3c6c7b7..09cfc94 100644 (file)
@@ -8,8 +8,9 @@ use parent 'CafeInsertion::Result::Coffee';
 require CafeInsertion::Result::Sugar;
 
 __PACKAGE__->table('sumatra');
+__PACKAGE__->result_source_instance->deploy_depends_on(["CafeInsertion::Result::Coffee"]);
 __PACKAGE__->result_source_instance->add_additional_parents(
-    "CafeInsertion::Result::Sugar");
+    "CafeInsertion::Result::Sugar","CafeInsertion::Result::Cream");
 __PACKAGE__->add_columns( "aroma", { data_type => "text" } );
 
 __PACKAGE__->has_many(
index e236be3..a06ab16 100644 (file)
@@ -8,7 +8,7 @@ use parent 'LoadTest::Result::Foo';
 require LoadTest::Result::Mixin;
 
 __PACKAGE__->table('bar');
-
+__PACKAGE__->result_source_instance->deploy_depends_on(["LoadTest::Result::Foo"]);
 __PACKAGE__->result_source_instance->add_additional_parents(
     "LoadTest::Result::Mixin" );
 
index 1bf4e54..d05669d 100644 (file)
@@ -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;
index e36e42a..0ccd9d7 100644 (file)
@@ -8,6 +8,7 @@ use parent 'NoSequenceSalad::Result::Salad';
 require NoSequenceSalad::Result::Dressing;
 
 __PACKAGE__->table('mesclun');
+__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" } );