8 my $schema = DBICTest->init_schema();
13 my $artist = $schema->resultset ('Artist')->first;
15 my $genre = $schema->resultset ('Genre')
16 ->create ({ name => 'par excellence' });
18 is ($genre->search_related( 'model_cd' )->count, 0, 'No cds yet');
21 $genre->update_or_create_related ('model_cd', {
24 title => 'the best thing since sliced bread',
27 # verify cd was inserted ok
28 is ($genre->search_related( 'model_cd' )->count, 1, 'One cd');
29 my $cd = $genre->find_related ('model_cd', {});
31 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
33 artist => $artist->id,
35 title => 'the best thing since sliced bread',
37 'CD created correctly',
40 # expect a year update on the only related row
41 # (non-qunique column + unique column as disambiguator)
42 $genre->update_or_create_related ('model_cd', {
44 title => 'the best thing since sliced bread',
47 # re-fetch the cd, verify update
48 is ($genre->search_related( 'model_cd' )->count, 1, 'Still one cd');
49 $cd = $genre->find_related ('model_cd', {});
51 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
53 artist => $artist->id,
55 title => 'the best thing since sliced bread',
57 'CD year column updated correctly',
61 # expect an update of the only related row
62 # (update a unique column)
63 $genre->update_or_create_related ('model_cd', {
64 title => 'the best thing since vertical toasters',
67 # re-fetch the cd, verify update
68 is ($genre->search_related( 'model_cd' )->count, 1, 'Still one cd');
69 $cd = $genre->find_related ('model_cd', {});
71 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
73 artist => $artist->id,
75 title => 'the best thing since vertical toasters',
77 'CD title column updated correctly',
81 # expect a year update on the only related row
82 # (non-qunique column only)
83 $genre->update_or_create_related ('model_cd', {
87 # re-fetch the cd, verify update
88 is ($genre->search_related( 'model_cd' )->count, 1, 'Still one cd');
89 $cd = $genre->find_related ('model_cd', {});
91 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
93 artist => $artist->id,
95 title => 'the best thing since vertical toasters',
97 'CD year column updated correctly without a disambiguator',