4 use Test::More qw(no_plan);
8 my $schema = DBICTest->init_schema();
10 my $cd2 = $schema->resultset('CD')->create({ artist =>
11 { name => 'Fred Bloggs' },
16 is(ref $cd2->artist, 'DBICTest::Artist', 'Created CD and Artist object');
17 is($cd2->artist->name, 'Fred Bloggs', 'Artist created correctly');
19 my $artist = $schema->resultset('Artist')->create({ name => 'Fred 2',
21 { title => 'Music to code by',
26 is(ref $artist->cds->first, 'DBICTest::CD', 'Created Artist with CDs');
27 is($artist->cds->first->title, 'Music to code by', 'CD created correctly');
30 $artist->update({cds => [ $artist->cds,
31 { title => 'Yet another CD',
36 is(($artist->cds->search({}, { order_by => 'year' }))[0]->title, 'Yet another CD', 'Updated and added another CD');
38 my $newartist = $schema->resultset('Artist')->find_or_create({ name => 'Fred 2'});
40 is($newartist->name, 'Fred 2', 'Retrieved the artist');
43 my $newartist2 = $schema->resultset('Artist')->find_or_create({ name => 'Fred 3',
45 { title => 'Noah Act',
52 is($newartist2->name, 'Fred 3', 'Created new artist with cds via find_or_create');
57 my $artist = $schema->resultset('Artist')->first;
59 my $cd_result = $artist->create_related('cds', {
61 title => 'TestOneCD1',
75 ok( $cd_result && ref $cd_result eq 'DBICTest::CD', "Got Good CD Class");
76 ok( $cd_result->title eq "TestOneCD1", "Got Expected Title");
78 my $tracks = $cd_result->tracks;
80 ok( ref $tracks eq "DBIx::Class::ResultSet", "Got Expected Tracks ResultSet");
82 foreach my $track ($tracks->all)
84 ok( $track && ref $track eq 'DBICTest::Track', 'Got Expected Track Class');
90 my $artist = $schema->resultset('Artist')->first;
92 my $cd_result = $artist->create_related('cds', {
94 title => 'TestOneCD2',
106 liner_notes => { notes => 'I can haz liner notes?' },
110 ok( $cd_result && ref $cd_result eq 'DBICTest::CD', "Got Good CD Class");
111 ok( $cd_result->title eq "TestOneCD2", "Got Expected Title");
112 ok( $cd_result->notes eq 'I can haz liner notes?', 'Liner notes');
114 my $tracks = $cd_result->tracks;
116 ok( ref $tracks eq "DBIx::Class::ResultSet", "Got Expected Tracks ResultSet");
118 foreach my $track ($tracks->all)
120 ok( $track && ref $track eq 'DBICTest::Track', 'Got Expected Track Class');