[Bast-commits] r7907 - in DBIx-Class/0.08/branches/view_rels/t: .
lib/DBICTest/Schema
ribasushi at dev.catalyst.perl.org
ribasushi at dev.catalyst.perl.org
Sun Nov 15 13:11:07 GMT 2009
Author: ribasushi
Date: 2009-11-15 13:11:03 +0000 (Sun, 15 Nov 2009)
New Revision: 7907
Modified:
DBIx-Class/0.08/branches/view_rels/t/104view.t
DBIx-Class/0.08/branches/view_rels/t/lib/DBICTest/Schema/Track.pm
DBIx-Class/0.08/branches/view_rels/t/lib/DBICTest/Schema/Year1999CDs.pm
Log:
Extensive test of virtual and classic view relationships
Modified: DBIx-Class/0.08/branches/view_rels/t/104view.t
===================================================================
--- DBIx-Class/0.08/branches/view_rels/t/104view.t 2009-11-15 13:10:10 UTC (rev 7906)
+++ DBIx-Class/0.08/branches/view_rels/t/104view.t 2009-11-15 13:11:03 UTC (rev 7907)
@@ -1,5 +1,5 @@
use strict;
-use warnings;
+use warnings;
use Test::More;
use Test::Exception;
@@ -8,8 +8,6 @@
my $schema = DBICTest->init_schema();
-plan tests => 2;
-
## Real view
my $cds_rs_2000 = $schema->resultset('CD')->search( { year => 2000 });
my $year2kcds_rs = $schema->resultset('Year2000CDs');
@@ -24,5 +22,50 @@
is($cds_rs_1999->count, $year1999cds_rs->count, 'View Year1999CDs sees all CDs in year 1999');
+# Test if relationships work correctly
+is_deeply (
+ [
+ $schema->resultset('Year1999CDs')->search (
+ {},
+ {
+ result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+ prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ],
+ },
+ )->all
+ ],
+ [
+ $schema->resultset('CD')->search (
+ { 'me.year' => '1999'},
+ {
+ result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+ prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ],
+ columns => [qw/cdid single_track title/], # to match the columns retrieved by the virtview
+ },
+ )->all
+ ],
+ 'Prefetch over virtual view gives expected result',
+);
+is_deeply (
+ [
+ $schema->resultset('Year2000CDs')->search (
+ {},
+ {
+ result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+ prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ],
+ },
+ )->all
+ ],
+ [
+ $schema->resultset('CD')->search (
+ { 'me.year' => '2000'},
+ {
+ result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+ prefetch => ['artist', { tracks => [qw/cd year1999cd year2000cd/] } ],
+ },
+ )->all
+ ],
+ 'Prefetch over regular view gives expected result',
+);
+done_testing;
Modified: DBIx-Class/0.08/branches/view_rels/t/lib/DBICTest/Schema/Track.pm
===================================================================
--- DBIx-Class/0.08/branches/view_rels/t/lib/DBICTest/Schema/Track.pm 2009-11-15 13:10:10 UTC (rev 7906)
+++ DBIx-Class/0.08/branches/view_rels/t/lib/DBICTest/Schema/Track.pm 2009-11-15 13:11:03 UTC (rev 7907)
@@ -54,11 +54,13 @@
"year1999cd",
"DBICTest::Schema::Year1999CDs",
{ "foreign.cdid" => "self.cd" },
+ { join_type => 'left' }, # the relationship is of course optional
);
__PACKAGE__->belongs_to(
"year2000cd",
"DBICTest::Schema::Year2000CDs",
{ "foreign.cdid" => "self.cd" },
+ { join_type => 'left' },
);
1;
Modified: DBIx-Class/0.08/branches/view_rels/t/lib/DBICTest/Schema/Year1999CDs.pm
===================================================================
--- DBIx-Class/0.08/branches/view_rels/t/lib/DBICTest/Schema/Year1999CDs.pm 2009-11-15 13:10:10 UTC (rev 7906)
+++ DBIx-Class/0.08/branches/view_rels/t/lib/DBICTest/Schema/Year1999CDs.pm 2009-11-15 13:11:03 UTC (rev 7907)
@@ -9,7 +9,7 @@
__PACKAGE__->table('year1999cds');
__PACKAGE__->result_source_instance->is_virtual(1);
__PACKAGE__->result_source_instance->view_definition(
- "SELECT cdid, artist, title FROM cd WHERE year ='1999'"
+ "SELECT cdid, artist, title, single_track FROM cd WHERE year ='1999'"
);
__PACKAGE__->add_columns(
'cdid' => {
@@ -23,7 +23,11 @@
data_type => 'varchar',
size => 100,
},
-
+ 'single_track' => {
+ data_type => 'integer',
+ is_nullable => 1,
+ is_foreign_key => 1,
+ },
);
__PACKAGE__->set_primary_key('cdid');
__PACKAGE__->add_unique_constraint([ qw/artist title/ ]);
More information about the Bast-commits
mailing list