{{ $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
$object = $self->find( $updates, { key => 'primary' } );
}
- $object = $self->new( {} )
+ $object = $self->new_result( {} )
unless defined $object;
# warn Dumper( $updates ); use Data::Dumper;
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 ) )
->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;
}
package DBSchema;
-# Created by DBIx::Class::Schema::Loader v0.03000 @ 2006-10-02 08:24:09
-
use strict;
use warnings;
-use base 'DBIx::Class::Schema';
-use DateTime;
+use base 'DBSchemaBase';
__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;
--- /dev/null
+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;
--- /dev/null
+package DBSchemaMoose;
+
+use strict;
+use warnings;
+
+use base 'DBSchemaBase';
+
+__PACKAGE__->load_namespaces(
+ result_namespace => '+DBSchema::Result',
+ default_resultset_class => '+DBSchemaMoose::ResultSet',
+);
+
+1;
--- /dev/null
+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;
--- /dev/null
+# -*- perl -*-
+
+use lib 't/lib';
+use DBSchemaMoose;
+use RunTests;
+use Test::More;
+
+my $schema = DBSchemaMoose->get_test_schema();
+
+run_tests( $schema);
+
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 );
use Test::More;
#unlink 't/var/dvdzbr.db';
-my $schema = DBSchema::get_test_schema();
+my $schema = DBSchema->get_test_schema();
run_tests( $schema );