]> Dogcows Code - chaz/p5-DBIx-Class-ResultSet-RecursiveUpdate/commitdiff
fixed usage with moosified resultsets (RT#64773)
authorAlexander Hartmaier <abraxxa@cpan.org>
Wed, 9 Feb 2011 17:14:46 +0000 (18:14 +0100)
committerAlexander Hartmaier <abraxxa@cpan.org>
Wed, 9 Feb 2011 17:14:46 +0000 (18:14 +0100)
Changes
lib/DBIx/Class/ResultSet/RecursiveUpdate.pm
t/lib/DBSchema.pm
t/lib/DBSchemaBase.pm [new file with mode: 0644]
t/lib/DBSchemaMoose.pm [new file with mode: 0644]
t/lib/DBSchemaMoose/ResultSet.pm [new file with mode: 0644]
t/moosified-rs.t [new file with mode: 0644]
t/pg.t
t/sqlite.t

diff --git a/Changes b/Changes
index 656f3cbbffc4e05e93543d431e531b18a571ef8d..bf46b91261fc35eaabe45c3c177bc9b4d0efd7f0 100644 (file)
--- a/Changes
+++ b/Changes
@@ -2,6 +2,7 @@ Revision history for DBIx::Class::ResultSet::RecursiveUpdate
 
 {{ $NEXT }}
     - Fixed updating of nullable has_many rels (RT#65561)
 
 {{ $NEXT }}
     - Fixed updating of nullable has_many rels (RT#65561)
+    - Fixed usage with moosified resultsets (RT#64773)
 
 0.21      2010-10-28 16:56:18 Europe/Vienna
     - Warn instead of throwing an exception if a key is neither
 
 0.21      2010-10-28 16:56:18 Europe/Vienna
     - Warn instead of throwing an exception if a key is neither
index c0db8b415ebac682e0a1bad8fe19b18722fb0604..94b1c07dde938807d001607ae6dfecd1e2e0c091 100644 (file)
@@ -107,7 +107,7 @@ sub recursive_update {
         $object = $self->find( $updates, { key => 'primary' } );
     }
 
         $object = $self->find( $updates, { key => 'primary' } );
     }
 
-    $object = $self->new( {} )
+    $object = $self->new_result( {} )
         unless defined $object;
 
     # warn Dumper( $updates ); use Data::Dumper;
         unless defined $object;
 
     # warn Dumper( $updates ); use Data::Dumper;
@@ -463,7 +463,7 @@ sub is_m2m {
     if ( $rclass->can('_m2m_metadata') ) {
         return $rclass->_m2m_metadata->{$relation};
     }
     if ( $rclass->can('_m2m_metadata') ) {
         return $rclass->_m2m_metadata->{$relation};
     }
-    my $object = $self->new( {} );
+    my $object = $self->new_result( {} );
     if (    $object->can($relation)
         and !$self->result_source->has_relationship($relation)
         and $object->can( 'set_' . $relation ) )
     if (    $object->can($relation)
         and !$self->result_source->has_relationship($relation)
         and $object->can( 'set_' . $relation ) )
@@ -484,7 +484,7 @@ sub get_m2m_source {
             ->related_source(
             $rclass->_m2m_metadata->{$relation}{foreign_relation} );
     }
             ->related_source(
             $rclass->_m2m_metadata->{$relation}{foreign_relation} );
     }
-    my $object = $self->new( {} );
+    my $object = $self->new_result( {} );
     my $r = $object->$relation;
     return $r->result_source;
 }
     my $r = $object->$relation;
     return $r->result_source;
 }
index af80fbf17373078aeabdc0b44267f47cec443ecb..3fa40d2d9d22e2f3eb41b23f7e9f8580a9cf30ae 100644 (file)
@@ -1,70 +1,11 @@
 package DBSchema;
 
 package DBSchema;
 
-# Created by DBIx::Class::Schema::Loader v0.03000 @ 2006-10-02 08:24:09
-
 use strict;
 use warnings;
 
 use strict;
 use warnings;
 
-use base 'DBIx::Class::Schema';
-use DateTime;
+use base 'DBSchemaBase';
 
 __PACKAGE__->load_namespaces( default_resultset_class => '+DBIx::Class::ResultSet::RecursiveUpdate' );
 
 
 __PACKAGE__->load_namespaces( default_resultset_class => '+DBIx::Class::ResultSet::RecursiveUpdate' );
 
-sub tables_exist {
-    my ( $dsn, $user, $pass ) = @_;
-    my $dbh = DBI->connect($dsn, $user, $pass, );
-    return $dbh->tables( '%', '%', 'dvd', );
-}
-
-
-sub get_test_schema {
-    my ( $dsn, $user, $pass ) = @_;
-    $dsn ||= 'dbi:SQLite:dbname=t/var/dvdzbr.db';
-    warn "testing $dsn\n";
-    my $schema = __PACKAGE__->connect( $dsn, $user, $pass, {} );
-    my $deploy_attrs;
-    $deploy_attrs->{add_drop_table} = 1 if tables_exist( $dsn, $user, $pass );
-    $schema->deploy( $deploy_attrs );
-    $schema->populate('Personality', [
-        [ qw/user_id / ],
-        [ '1'],
-        [ '2' ],
-        [ '3'],
-        ]
-    );
-    $schema->populate('User', [
-        [ qw/username name password / ],
-        [ 'jgda', 'Jonas Alves', ''],
-        [ 'isa' , 'Isa', '', ],
-        [ 'zby' , 'Zbyszek Lukasiak', ''],
-        ]
-    );
-    $schema->populate('Tag', [
-        [ qw/name file / ],
-        [ 'comedy', '' ],
-        [ 'dramat', '' ],
-        [ 'australian', '' ],
-        ]
-    );
-    $schema->populate('Dvd', [
-        [ qw/name imdb_id owner current_borrower creation_date alter_date / ],
-        [ 'Picnick under the Hanging Rock', 123, 1, 3, '2003-01-16 23:12:01', undef ],
-        [ 'The Deerhunter', 1234, 1, 1, undef, undef ],
-        [ 'Rejs', 1235, 3, 1, undef, undef ],
-        [ 'Seksmisja', 1236, 3, 1, undef, undef ],
-        ]
-    ); 
-    $schema->populate( 'Dvdtag', [
-        [ qw/ dvd tag / ],
-        [ 1, 2 ],
-        [ 1, 3 ],
-        [ 3, 1 ],
-        [ 4, 1 ],
-        ]
-    );
-    return $schema;
-}
-    
-    
 1;
 
 1;
 
diff --git a/t/lib/DBSchemaBase.pm b/t/lib/DBSchemaBase.pm
new file mode 100644 (file)
index 0000000..5b19a6e
--- /dev/null
@@ -0,0 +1,61 @@
+package DBSchemaBase;
+use strict;
+use warnings;
+
+use base 'DBIx::Class::Schema';
+
+sub tables_exist {
+    my $dbh = shift;
+    # assume that all tables exist if table dvd is found
+    return $dbh->tables( '%', '%', 'dvd' );
+}
+
+sub get_test_schema {
+    my ( $class, $dsn, $user, $pass ) = @_;
+    $dsn ||= 'dbi:SQLite:dbname=t/var/dvdzbr.db';
+    warn "testing $dsn\n";
+    my $schema = $class->connect( $dsn, $user, $pass, {} );
+    my $deploy_attrs;
+    $deploy_attrs->{add_drop_table} = 1 if tables_exist( $schema->storage->dbh );
+    $schema->deploy( $deploy_attrs );
+    $schema->populate('Personality', [
+        [ qw/user_id / ],
+        [ '1'],
+        [ '2' ],
+        [ '3'],
+        ]
+    );
+    $schema->populate('User', [
+        [ qw/username name password / ],
+        [ 'jgda', 'Jonas Alves', ''],
+        [ 'isa' , 'Isa', '', ],
+        [ 'zby' , 'Zbyszek Lukasiak', ''],
+        ]
+    );
+    $schema->populate('Tag', [
+        [ qw/name file / ],
+        [ 'comedy', '' ],
+        [ 'dramat', '' ],
+        [ 'australian', '' ],
+        ]
+    );
+    $schema->populate('Dvd', [
+        [ qw/name imdb_id owner current_borrower creation_date alter_date / ],
+        [ 'Picnick under the Hanging Rock', 123, 1, 3, '2003-01-16 23:12:01', undef ],
+        [ 'The Deerhunter', 1234, 1, 1, undef, undef ],
+        [ 'Rejs', 1235, 3, 1, undef, undef ],
+        [ 'Seksmisja', 1236, 3, 1, undef, undef ],
+        ]
+    );
+    $schema->populate( 'Dvdtag', [
+        [ qw/ dvd tag / ],
+        [ 1, 2 ],
+        [ 1, 3 ],
+        [ 3, 1 ],
+        [ 4, 1 ],
+        ]
+    );
+    return $schema;
+}
+
+1;
diff --git a/t/lib/DBSchemaMoose.pm b/t/lib/DBSchemaMoose.pm
new file mode 100644 (file)
index 0000000..d662624
--- /dev/null
@@ -0,0 +1,13 @@
+package DBSchemaMoose;
+
+use strict;
+use warnings;
+
+use base 'DBSchemaBase';
+
+__PACKAGE__->load_namespaces(
+    result_namespace => '+DBSchema::Result',
+    default_resultset_class => '+DBSchemaMoose::ResultSet',
+);
+
+1;
diff --git a/t/lib/DBSchemaMoose/ResultSet.pm b/t/lib/DBSchemaMoose/ResultSet.pm
new file mode 100644 (file)
index 0000000..6bb411e
--- /dev/null
@@ -0,0 +1,7 @@
+package DBSchemaMoose::ResultSet;
+use namespace::autoclean;
+use Moose;
+use MooseX::NonMoose;
+extends qw/DBIx::Class::ResultSet::RecursiveUpdate DBIx::Class::ResultSet/;
+__PACKAGE__->meta->make_immutable;
+1;
diff --git a/t/moosified-rs.t b/t/moosified-rs.t
new file mode 100644 (file)
index 0000000..c902048
--- /dev/null
@@ -0,0 +1,11 @@
+# -*- perl -*-
+
+use lib 't/lib';
+use DBSchemaMoose;
+use RunTests;
+use Test::More;
+
+my $schema = DBSchemaMoose->get_test_schema();
+
+run_tests( $schema);
+
diff --git a/t/pg.t b/t/pg.t
index 7a2294d69ae8631094ec6d887a9e3c198cb52d39..7c4f05115736d6dc8d8b09cf418a214618526f4d 100644 (file)
--- a/t/pg.t
+++ b/t/pg.t
@@ -10,7 +10,7 @@ my ($dsn, $user, $pass) = @ENV{map { "DBICTEST_PG_${_}" } qw/DSN USER PASS/};
 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
  . ' (note: creates and tables!)' unless ($dsn && $user);
 
 plan skip_all => 'Set $ENV{DBICTEST_PG_DSN}, _USER and _PASS to run this test'
  . ' (note: creates and tables!)' unless ($dsn && $user);
 
-my $schema = DBSchema::get_test_schema( $dsn, $user, $pass );
+my $schema = DBSchema->get_test_schema( $dsn, $user, $pass );
 
 run_tests( $schema );
 
 
 run_tests( $schema );
 
index ca3e72e494115cd2ead4661df7b98342f047501b..93baaed30ccd5fadf484571a7306c8e1572dfb8f 100644 (file)
@@ -6,6 +6,6 @@ use RunTests;
 use Test::More;
 
 #unlink 't/var/dvdzbr.db';
 use Test::More;
 
 #unlink 't/var/dvdzbr.db';
-my $schema = DBSchema::get_test_schema();
+my $schema = DBSchema->get_test_schema();
 run_tests( $schema );
 
 run_tests( $schema );
 
This page took 0.030094 seconds and 4 git commands to generate.