8 my $schema = DBICTest->init_schema();
12 my $artist = $schema->resultset ('Artist')->first;
14 my $genre = $schema->resultset ('Genre')
15 ->create ({ name => 'par excellence' });
17 is ($genre->search_related( 'model_cd' )->count, 0, 'No cds yet');
20 $genre->update_or_create_related ('model_cd', {
23 title => 'the best thing since sliced bread',
26 # verify cd was inserted ok
27 is ($genre->search_related( 'model_cd' )->count, 1, 'One cd');
28 my $cd = $genre->find_related ('model_cd', {});
30 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
32 artist => $artist->id,
34 title => 'the best thing since sliced bread',
36 'CD created correctly',
39 # expect a year update on the only related row
40 # (non-qunique column + unique column as disambiguator)
41 $genre->update_or_create_related ('model_cd', {
43 title => 'the best thing since sliced bread',
46 # re-fetch the cd, verify update
47 is ($genre->search_related( 'model_cd' )->count, 1, 'Still one cd');
48 $cd = $genre->find_related ('model_cd', {});
50 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
52 artist => $artist->id,
54 title => 'the best thing since sliced bread',
56 'CD year column updated correctly',
60 # expect an update of the only related row
61 # (update a unique column)
62 $genre->update_or_create_related ('model_cd', {
63 title => 'the best thing since vertical toasters',
66 # re-fetch the cd, verify update
67 is ($genre->search_related( 'model_cd' )->count, 1, 'Still one cd');
68 $cd = $genre->find_related ('model_cd', {});
70 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
72 artist => $artist->id,
74 title => 'the best thing since vertical toasters',
76 'CD title column updated correctly',
80 # expect a year update on the only related row
81 # (non-unique column only)
82 $genre->update_or_create_related ('model_cd', {
86 # re-fetch the cd, verify update
87 is ($genre->search_related( 'model_cd' )->count, 1, 'Still one cd');
88 $cd = $genre->find_related ('model_cd', {});
90 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
92 artist => $artist->id,
94 title => 'the best thing since vertical toasters',
96 'CD year column updated correctly without a disambiguator',