DBIx-Class
view release on metacpan or search on metacpan
t/101populate_rs.t view on Meta::CPAN
cds => [
{ title => 'My First CD', year => 2006 },
{ title => 'Yet More Tweeny-Pop crap', year => 2007 },
],
},
{
name => 'Manufactured Crap',
},
{
name => 'Like I Give a Damn',
cds => [
{ title => 'My parents sold me to a record company' ,year => 2005 },
{ title => 'Why Am I So Ugly?', year => 2006 },
{ title => 'I Got Surgery and am now Popular', year => 2007 }
],
},
{
name => 'Formerly Named',
cds => [
{ title => 'One Hit Wonder', year => 2006 },
],
},
];
## Get the result row objects.
my ($girl, $crap, $damn, $formerly) = $art_rs->populate($artists);
## Do we have the right object?
isa_ok( $crap, 'DBICTest::Artist', "Got 'Artist'");
isa_ok( $girl, 'DBICTest::Artist', "Got 'Artist'");
isa_ok( $damn, 'DBICTest::Artist', "Got 'Artist'");
isa_ok( $formerly, 'DBICTest::Artist', "Got 'Artist'");
## Find the expected information?
ok( $crap->name eq 'Manufactured Crap', "Got Correct name for result object");
ok( $girl->name eq 'Angsty-Whiny Girl', "Got Correct name for result object");
ok( $damn->name eq 'Like I Give a Damn', "Got Correct name for result object");
ok( $formerly->name eq 'Formerly Named', "Got Correct name for result object");
## Create the expected children sub objects?
ok( $crap->cds->count == 0, "got Expected Number of Cds");
ok( $girl->cds->count == 2, "got Expected Number of Cds");
ok( $damn->cds->count == 3, "got Expected Number of Cds");
ok( $formerly->cds->count == 1, "got Expected Number of Cds");
## Did the cds get expected information?
my ($cd1, $cd2) = $girl->cds->search({},{order_by=>'year'});
ok( $cd1->title eq "My First CD", "Got Expected CD Title");
ok( $cd2->title eq "Yet More Tweeny-Pop crap", "Got Expected CD Title");
}
HAS_MANY_WITH_PKS: {
## This group tests the ability to specify the PK in the parent and let
## DBIC transparently pass the PK down to the Child and also let's the
## child create any other needed PK's for itself.
my $aid = $art_rs->get_column('artistid')->max || 0;
my $first_aid = ++$aid;
my $artists = [
{
artistid => $first_aid,
name => 'PK_Angsty-Whiny Girl',
cds => [
{ artist => $first_aid, title => 'PK_My First CD', year => 2006 },
{ artist => $first_aid, title => 'PK_Yet More Tweeny-Pop crap', year => 2007 },
],
},
{
artistid => ++$aid,
name => 'PK_Manufactured Crap',
},
{
artistid => ++$aid,
name => 'PK_Like I Give a Damn',
cds => [
{ title => 'PK_My parents sold me to a record company' ,year => 2005 },
{ title => 'PK_Why Am I So Ugly?', year => 2006 },
{ title => 'PK_I Got Surgery and am now Popular', year => 2007 }
],
},
{
artistid => ++$aid,
name => 'PK_Formerly Named',
cds => [
{ title => 'PK_One Hit Wonder', year => 2006 },
],
},
];
## Get the result row objects.
my ($girl, $crap, $damn, $formerly) = $art_rs->populate($artists);
## Do we have the right object?
isa_ok( $crap, 'DBICTest::Artist', "Got 'Artist'");
isa_ok( $girl, 'DBICTest::Artist', "Got 'Artist'");
isa_ok( $damn, 'DBICTest::Artist', "Got 'Artist'");
isa_ok( $formerly, 'DBICTest::Artist', "Got 'Artist'");
## Find the expected information?
ok( $crap->name eq 'PK_Manufactured Crap', "Got Correct name for result object");
ok( $girl->name eq 'PK_Angsty-Whiny Girl', "Got Correct name for result object");
ok( $girl->artistid == $first_aid, "Got Correct artist PK for result object");
ok( $damn->name eq 'PK_Like I Give a Damn', "Got Correct name for result object");
ok( $formerly->name eq 'PK_Formerly Named', "Got Correct name for result object");
## Create the expected children sub objects?
ok( $crap->cds->count == 0, "got Expected Number of Cds");
ok( $girl->cds->count == 2, "got Expected Number of Cds");
( run in 2.294 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )