[Bast-commits] r7373 - DBIx-Class/0.08/branches/prefetch/t/prefetch
mo at dev.catalyst.perl.org
mo at dev.catalyst.perl.org
Mon Aug 24 13:36:31 GMT 2009
Author: mo
Date: 2009-08-24 13:36:31 +0000 (Mon, 24 Aug 2009)
New Revision: 7373
Modified:
DBIx-Class/0.08/branches/prefetch/t/prefetch/multiple_hasmany.t
Log:
added crazy prefetch test
Modified: DBIx-Class/0.08/branches/prefetch/t/prefetch/multiple_hasmany.t
===================================================================
--- DBIx-Class/0.08/branches/prefetch/t/prefetch/multiple_hasmany.t 2009-08-24 13:11:52 UTC (rev 7372)
+++ DBIx-Class/0.08/branches/prefetch/t/prefetch/multiple_hasmany.t 2009-08-24 13:36:31 UTC (rev 7373)
@@ -10,9 +10,6 @@
my $schema = DBICTest->init_schema();
my $sdebug = $schema->storage->debug;
-local $TODO =
-'Prefetch of multiple has_many rels at the same level (currently warn to protect the clueless git)';
-
#( 1 -> M + M )
my $cd_rs =
$schema->resultset('CD')->search( { 'me.title' => 'Forkful of bees' } );
@@ -86,5 +83,261 @@
'equal amount of objects with and without prefetch over several same level has_many\'s (M -> 1 -> M + M)'
);
+# $artist_rs->search(
+# {},
+# {
+# prefetch => [
+# {
+# cds => [
+# { tracks => 'cd_single' },
+# { producer_to_cd => 'producer' }
+# ]
+# },
+# { artwork_to_artist => 'artwork' } ] );
+
+my $cd = $schema->resultset('Artist')->create(
+ {
+ name => 'mo',
+ rank => '1337',
+ cds => [
+ {
+ artist => 4,
+ title => 'Song of a Foo',
+ year => '1999',
+ tracks => [
+ {
+ position => 1,
+ title => 'Foo Me Baby One More Time',
+ cd_single =>
+ { artist => 6, title => 'MO! Single', year => 2001 }
+ },
+ {
+ position => 2,
+ title => 'Foo Me Baby One More Time II',
+ },
+ {
+ position => 3,
+ title => 'Foo Me Baby One More Time III',
+ },
+ {
+ position => 4,
+ title => 'Foo Me Baby One More Time IV',
+ }
+ ],
+ cd_to_producer => [
+ { producer => { name => 'riba' } },
+ { producer => { name => 'sushi' } },
+ ]
+ },
+ {
+ artist => 4,
+ title => 'Song of a Foo II',
+ year => '2002',
+ tracks => [
+ {
+ position => 1,
+ title => 'Quit Playing Games With My Heart',
+ cd_single =>
+ { artist => 5, title => 'MO! Single', year => 2001 }
+ },
+ {
+ position => 2,
+ title => 'Bar Foo',
+ },
+ {
+ position => 3,
+ title => 'Foo Bar',
+ }
+ ],
+ cd_to_producer => [ { producer => 4 }, { producer => 5 }, ]
+ }
+ ],
+ artwork_to_artist =>
+ [ { artwork => { cd_id => 1 } }, { artwork => { cd_id => 2 } } ]
+ }
+);
+
+my $mo = $schema->resultset('Artist')->search(
+ undef,
+ {
+ result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+ prefetch => [
+ {
+ cds => [
+ { tracks => 'cd_single' },
+ { cd_to_producer => 'producer' }
+ ]
+ },
+ { artwork_to_artist => 'artwork' }
+ ]
+ }
+)->find(4);
+
+is( scalar @{ $mo->{cds} }, 2, 'two CDs' );
+
+is_deeply(
+ $mo,
+ {
+ 'cds' => [
+ {
+ 'single_track' => undef,
+ 'tracks' => [
+ {
+ 'small_dt' => undef,
+ 'cd' => '6',
+ 'position' => '1',
+ 'trackid' => '19',
+ 'title' => 'Foo Me Baby One More Time',
+ 'cd_single' => {
+ 'single_track' => '19',
+ 'artist' => '6',
+ 'cdid' => '7',
+ 'title' => 'MO! Single',
+ 'genreid' => undef,
+ 'year' => '2001'
+ },
+ 'last_updated_on' => undef,
+ 'last_updated_at' => undef
+ },
+ {
+ 'small_dt' => undef,
+ 'cd' => '6',
+ 'position' => '2',
+ 'trackid' => '20',
+ 'title' => 'Foo Me Baby One More Time II',
+ 'cd_single' => undef,
+ 'last_updated_on' => undef,
+ 'last_updated_at' => undef
+ },
+ {
+ 'small_dt' => undef,
+ 'cd' => '6',
+ 'position' => '3',
+ 'trackid' => '21',
+ 'title' => 'Foo Me Baby One More Time III',
+ 'cd_single' => undef,
+ 'last_updated_on' => undef,
+ 'last_updated_at' => undef
+ },
+ {
+ 'small_dt' => undef,
+ 'cd' => '6',
+ 'position' => '4',
+ 'trackid' => '22',
+ 'title' => 'Foo Me Baby One More Time IV',
+ 'cd_single' => undef,
+ 'last_updated_on' => undef,
+ 'last_updated_at' => undef
+ }
+ ],
+ 'artist' => '4',
+ 'cdid' => '6',
+ 'cd_to_producer' => [
+ {
+ 'attribute' => undef,
+ 'cd' => '6',
+ 'producer' => {
+ 'name' => 'riba',
+ 'producerid' => '4'
+ }
+ },
+ {
+ 'attribute' => undef,
+ 'cd' => '6',
+ 'producer' => {
+ 'name' => 'sushi',
+ 'producerid' => '5'
+ }
+ }
+ ],
+ 'title' => 'Song of a Foo',
+ 'genreid' => undef,
+ 'year' => '1999'
+ },
+ {
+ 'single_track' => undef,
+ 'tracks' => [
+ {
+ 'small_dt' => undef,
+ 'cd' => '8',
+ 'position' => '2',
+ 'trackid' => '24',
+ 'title' => 'Bar Foo',
+ 'cd_single' => undef,
+ 'last_updated_on' => undef,
+ 'last_updated_at' => undef
+ },
+ {
+ 'small_dt' => undef,
+ 'cd' => '8',
+ 'position' => '3',
+ 'trackid' => '25',
+ 'title' => 'Foo Bar',
+ 'cd_single' => undef,
+ 'last_updated_on' => undef,
+ 'last_updated_at' => undef
+ },
+ {
+ 'small_dt' => undef,
+ 'cd' => '8',
+ 'position' => '1',
+ 'trackid' => '23',
+ 'title' => 'Quit Playing Games With My Heart',
+ 'cd_single' => {
+ 'single_track' => '23',
+ 'artist' => '5',
+ 'cdid' => '9',
+ 'title' => 'MO! Single',
+ 'genreid' => undef,
+ 'year' => '2001'
+ },
+ 'last_updated_on' => undef,
+ 'last_updated_at' => undef
+ }
+ ],
+ 'artist' => '4',
+ 'cdid' => '8',
+ 'cd_to_producer' => [
+ {
+ 'attribute' => undef,
+ 'cd' => '8',
+ 'producer' => {
+ 'name' => 'riba',
+ 'producerid' => '4'
+ }
+ },
+ {
+ 'attribute' => undef,
+ 'cd' => '8',
+ 'producer' => {
+ 'name' => 'sushi',
+ 'producerid' => '5'
+ }
+ }
+ ],
+ 'title' => 'Song of a Foo II',
+ 'genreid' => undef,
+ 'year' => '2002'
+ }
+ ],
+ 'artistid' => '4',
+ 'charfield' => undef,
+ 'name' => 'mo',
+ 'artwork_to_artist' => [
+ {
+ 'artwork' => { 'cd_id' => '1' },
+ 'artist_id' => '4',
+ 'artwork_cd_id' => '1'
+ },
+ {
+ 'artwork' => { 'cd_id' => '2' },
+ 'artist_id' => '4',
+ 'artwork_cd_id' => '2'
+ }
+ ],
+ 'rank' => '1337'
+ }
+);
+
done_testing;
More information about the Bast-commits
mailing list