From: Brandon Black Date: Tue, 31 Jan 2006 03:02:07 +0000 (+0000) Subject: storage->disconnect and new tests for out-of-line implicit rels X-Git-Tag: 0.03000~30 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=52bf3f264b3d5e1a0c494e82e13fb377eaa28a6f;p=dbsrgits%2FDBIx-Class-Schema-Loader.git storage->disconnect and new tests for out-of-line implicit rels --- diff --git a/TODO b/TODO index db0a04c..73ab417 100644 --- a/TODO +++ b/TODO @@ -2,7 +2,6 @@ Reminders to myself or whoever else ever looks in here... SQLite needs some heavy refactoring, the subroutines are becoming too complex to understand easily. -MySQL needs implicit FK support, I think. Consider: If local column is UNIQUE or PK, use has_one() for relation? diff --git a/lib/DBIx/Class/Schema/Loader/Generic.pm b/lib/DBIx/Class/Schema/Loader/Generic.pm index 2e26292..c27538a 100644 --- a/lib/DBIx/Class/Schema/Loader/Generic.pm +++ b/lib/DBIx/Class/Schema/Loader/Generic.pm @@ -143,7 +143,7 @@ sub new { warn qq/\### END DBIx::Class::Schema::Loader dump ###\n/ if $self->debug; - $self->schema->storage->dbh->disconnect; # XXX this should be ->storage->disconnect later? + $self->schema->storage->disconnect; $self; } diff --git a/t/11mysql_common.t b/t/11mysql_common.t index bc6f413..dac7a51 100644 --- a/t/11mysql_common.t +++ b/t/11mysql_common.t @@ -10,14 +10,15 @@ my $test_innodb = $ENV{DBICTEST_MYSQL_INNODB} || 0; my $skip_rels_msg = 'You need to set the DBICTEST_MYSQL_INNODB environment variable to test relationships'; my $tester = dbixcsl_common_tests->new( - vendor => 'Mysql', - auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT', - innodb => $test_innodb ? q{Engine=InnoDB} : 0, - dsn => $dsn, - user => $user, - password => $password, - skip_rels => $test_innodb ? 0 : $skip_rels_msg, - no_inline_rels => 1, + vendor => 'Mysql', + auto_inc_pk => 'INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT', + innodb => $test_innodb ? q{Engine=InnoDB} : 0, + dsn => $dsn, + user => $user, + password => $password, + skip_rels => $test_innodb ? 0 : $skip_rels_msg, + no_inline_rels => 1, + no_implicit_rels => 1, ); if( !$dsn || !$user ) { diff --git a/t/dbixcsl_common_tests.pm b/t/dbixcsl_common_tests.pm index 1a35c10..0e05127 100644 --- a/t/dbixcsl_common_tests.pm +++ b/t/dbixcsl_common_tests.pm @@ -37,7 +37,7 @@ sub skip_tests { sub run_tests { my $self = shift; - plan tests => 38; + plan tests => 41; $self->create(); @@ -105,7 +105,7 @@ sub run_tests { is( $obj2->id, 2 ); SKIP: { - skip $self->{skip_rels}, 25 if $self->{skip_rels}; + skip $self->{skip_rels}, 28 if $self->{skip_rels}; my $moniker3 = $monikers->{loader_test3}; my $class3 = $classes->{loader_test3}; @@ -228,6 +228,24 @@ sub run_tests { isa_ok( $obj13->loader_test12, $class12); isa_ok( $obj13->dat, $class12); } + + SKIP: { + skip 'This vendor cannot do out-of-line implicit rel defs', 3 + if $self->{no_implicit_rels}; + my $moniker14 = $monikers->{loader_test14}; + my $class14 = $classes->{loader_test14}; + my $rsobj14 = $conn->resultset($moniker14); + + my $moniker15 = $monikers->{loader_test15}; + my $class15 = $classes->{loader_test15}; + my $rsobj15 = $conn->resultset($moniker15); + + isa_ok( $rsobj14, "DBIx::Class::ResultSet" ); + isa_ok( $rsobj15, "DBIx::Class::ResultSet" ); + + my $obj15 = $rsobj15->find(1); + isa_ok( $obj15->loader_test14, $class14 ); + } } } @@ -405,6 +423,27 @@ sub create { ); + my @statements_implicit_rels = ( + qq{ + CREATE TABLE loader_test14 ( + id INTEGER NOT NULL PRIMARY KEY, + dat VARCHAR(8) + ) $self->{innodb} + }, + + q{ INSERT INTO loader_test14 (id,dat) VALUES (123,'aaa') }, + + qq{ + CREATE TABLE loader_test15 ( + id INTEGER NOT NULL PRIMARY KEY, + loader_test14 INTEGER NOT NULL, + FOREIGN KEY (loader_test14) REFERENCES loader_test14 + ) $self->{innodb} + }, + + q{ INSERT INTO loader_test15 (id,loader_test14) VALUES (1,123) }, + ); + $self->drop_tables; $self->{created} = 1; @@ -425,6 +464,9 @@ sub create { unless($self->{no_inline_rels}) { $dbh->do($_) for (@statements_inline_rels); } + unless($self->{no_implicit_rels}) { + $dbh->do($_) for (@statements_implicit_rels); + } } $dbh->disconnect(); } @@ -459,6 +501,11 @@ sub drop_tables { loader_test12 /; + my @tables_implicit_rels = qw/ + loader_test15 + loader_test14 + /; + my $drop_fk_mysql = q{ALTER TABLE loader_test10 DROP FOREIGN KEY loader_test11_fk;}; @@ -481,6 +528,9 @@ sub drop_tables { unless($self->{no_inline_rels}) { $dbh->do("DROP TABLE $_") for (@tables_inline_rels); } + unless($self->{no_implicit_rels}) { + $dbh->do("DROP TABLE $_") for (@tables_implicit_rels); + } } $dbh->do("DROP TABLE $_") for (@tables); $dbh->disconnect;