8 my $schema = DBICTest->init_schema();
12 my $cd2 = $schema->resultset('CD')->create({ artist =>
13 { name => 'Fred Bloggs' },
18 is(ref $cd2->artist, 'DBICTest::Artist', 'Created CD and Artist object');
19 is($cd2->artist->name, 'Fred Bloggs', 'Artist created correctly');
21 my $artist = $schema->resultset('Artist')->create({ name => 'Fred 2',
23 { title => 'Music to code by',
28 is(ref $artist->cds->first, 'DBICTest::CD', 'Created Artist with CDs');
29 is($artist->cds->first->title, 'Music to code by', 'CD created correctly');
32 $artist->update({cds => [ $artist->cds,
33 { title => 'Yet another CD',
38 is(($artist->cds->search({}, { order_by => 'year' }))[0]->title, 'Yet another CD', 'Updated and added another CD');
40 my $newartist = $schema->resultset('Artist')->find_or_create({ name => 'Fred 2'});
42 is($newartist->name, 'Fred 2', 'Retrieved the artist');
45 my $newartist2 = $schema->resultset('Artist')->find_or_create({ name => 'Fred 3',
47 { title => 'Noah Act',
54 is($newartist2->name, 'Fred 3', 'Created new artist with cds via find_or_create');
59 my $artist = $schema->resultset('Artist')->first;
61 my $cd_result = $artist->create_related('cds', {
63 title => 'TestOneCD1',
77 ok( $cd_result && ref $cd_result eq 'DBICTest::CD', "Got Good CD Class");
78 ok( $cd_result->title eq "TestOneCD1", "Got Expected Title");
80 my $tracks = $cd_result->tracks;
82 ok( ref $tracks eq "DBIx::Class::ResultSet", "Got Expected Tracks ResultSet");
84 foreach my $track ($tracks->all)
86 ok( $track && ref $track eq 'DBICTest::Track', 'Got Expected Track Class');
92 my $artist = $schema->resultset('Artist')->first;
94 my $cd_result = $artist->create_related('cds', {
96 title => 'TestOneCD2',
110 ok( $cd_result && ref $cd_result eq 'DBICTest::CD', "Got Good CD Class");
111 ok( $cd_result->title eq "TestOneCD2", "Got Expected Title");
113 my $tracks = $cd_result->tracks;
115 ok( ref $tracks eq "DBIx::Class::ResultSet", "Got Expected Tracks ResultSet");
117 foreach my $track ($tracks->all)
119 ok( $track && ref $track eq 'DBICTest::Track', 'Got Expected Track Class');