Extend Cafe tests.
[dbsrgits/DBIx-Class-ResultSource-MultipleTableInheritance.git] / lib / DBIx / Class / ResultSource / MultipleTableInheritance.pm
index d492490..6e948f7 100644 (file)
@@ -276,7 +276,7 @@ BEGIN {
 
   *names_of = sub (@cols) { map $_->{name}, @cols };
 
-  *function_body = sub ($name, $args, $body_parts) {
+  *functionbody = sub ($name, $args, $body_parts) {
     my $arglist = join(
       ', ',
         map "_${\$_->{name}} ${\uc($_->{data_type})}",
@@ -368,7 +368,7 @@ method view_definition () {
   # NOTE: this assumes a single PK col called id with a sequence somewhere
   # but nothing else -should- so fixing this should make everything work
   my $insert_func =
-    function_body
+    functionbody
       $self->name.'_insert',
       \@body_cols,
       [
@@ -396,7 +396,7 @@ method view_definition () {
   # UPDATE function
 
   my $update_func =
-    function_body
+    functionbody
       $self->name.'_update',
       [ @pk_cols, @body_cols ],
       [ map $sqla->update(
@@ -409,7 +409,7 @@ method view_definition () {
   # DELETE function
 
   my $delete_func =
-    function_body
+    functionbody
       $self->name.'_delete',
       [ @pk_cols ],
       [ map $sqla->delete($_->name, $pk_where), @sources ];
@@ -438,27 +438,21 @@ This only works with PostgreSQL for the moment.
 =head1 SYNOPSIS
 
     {
-        package MyApp::Schema::Result::Coffee;
+        package Cafe::Result::Coffee;
 
-        __PACKAGE__->table_class(
-            'DBIx::Class::ResultSource::MultipleTableInheritance'
-        );
+        use strict;
+        use warnings;
+        use parent 'DBIx::Class::Core';
+        use aliased 'DBIx::Class::ResultSource::MultipleTableInheritance'
+            => 'MTI';
+
+        __PACKAGE__->table_class(MTI);
         __PACKAGE__->table('coffee');
         __PACKAGE__->add_columns(
-          "id",
-          {
-            data_type => "integer",
-            default_value => "nextval('coffee_seq'::regclass)",
-            is_auto_increment => 1,
-            is_foreign_key => 1,
-            is_nullable => 0,
-            size => 4,
-          },
-          "flavor",
-          {
-            data_type => "text",
-            default_value => "good",
-          },
+            "id", { data_type => "integer" },
+            "flavor", {
+                data_type => "text",
+                default_value => "good" },
         );
 
         __PACKAGE__->set_primary_key("id");
@@ -467,19 +461,14 @@ This only works with PostgreSQL for the moment.
     }
 
     {
-        package MyApp::Schema::Result::Sumatra;
+        package Cafe::Result::Sumatra;
 
-        use parent 'Coffee';
+        use parent 'Cafe::Result::Coffee';
 
         __PACKAGE__->table('sumatra');
 
-        __PACKAGE__->add_columns(
-          "aroma",
-          {
-            data_type => "text",
-            default_value => undef,
-            is_nullable => 0,
-          },
+        __PACKAGE__->add_columns( "aroma",
+            { data_type => "text" }
         );
 
         1;
@@ -487,16 +476,16 @@ This only works with PostgreSQL for the moment.
     
     ...
 
-    my $schema = MyApp::Schema->connect($dsn);
-
-    my $cup = $schema->resultset('Sumatra')->new;
+    my $schema = Cafe->connect($dsn,$user,$pass);
 
-    print STDERR DwarnS $cup->columns;
+    my $cup = $schema->resultset('Sumatra');
 
-        $VAR1 = 'id';
-        $VAR2 = 'flavor';
-        $VAR3 = 'aroma';
+    print STDERR Dwarn $cup->result_source->columns;
 
+        "id"
+        "flavor"
+        "aroma"
+        ..
 
 Inherit from this package and you can make a resultset class from a view, but
 that's more than a little bit misleading: the result is B<transparently