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');
124 my $cdp = $schema->resultset('CD_to_Producer')->create({
125 cd => { artist => 1, title => 'foo', year => 2000 },
126 producer => { name => 'jorge' }
129 ok($cdp, 'join table record created ok');
132 my $kurt_cobain = { name => 'Kurt Cobain' };
134 my $in_utero = $schema->resultset('CD')->new({
139 $kurt_cobain->{cds} = [ $in_utero ];
142 $schema->resultset('Artist')->populate([ $kurt_cobain ]); # %)
143 $a = $schema->resultset('Artist')->find({name => 'Kurt Cobain'});
145 is($a->name, 'Kurt Cobain', 'Artist insertion ok');
146 is($a->cds && $a->cds->first && $a->cds->first->title,
147 'In Utero', 'CD insertion ok');
151 my $pink_floyd = { name => 'Pink Floyd' };
153 my $the_wall = { title => 'The Wall', year => 1979 };
155 $pink_floyd->{cds} = [ $the_wall ];
158 $schema->resultset('Artist')->populate([ $pink_floyd ]); # %)
159 $a = $schema->resultset('Artist')->find({name => 'Pink Floyd'});
161 is($a->name, 'Pink Floyd', 'Artist insertion ok');
162 is($a->cds && $a->cds->first->title, 'The Wall', 'CD insertion ok');