8 use DBIC::SqlMakerTest;
10 my $schema = DBICTest->init_schema();
15 my $artist = $schema->resultset ('Artist')->first;
17 my $genre = $schema->resultset ('Genre')
18 ->create ({ name => 'par excellence' });
20 is ($genre->search_related( 'cds' )->count, 0, 'No cds yet');
23 $genre->update_or_create_related ('cds', {
26 title => 'the best thing since sliced bread',
29 # verify cd was inserted ok
30 is ($genre->search_related( 'cds' )->count, 1, 'One cd');
31 my $cd = $genre->find_related ('cds', {});
33 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
35 artist => $artist->id,
37 title => 'the best thing since sliced bread',
39 'CD created correctly',
42 # expect a year update on the only related row
43 # (non-qunique column + unique column as disambiguator)
44 $genre->update_or_create_related ('cds', {
46 title => 'the best thing since sliced bread',
49 # re-fetch the cd, verify update
50 is ($genre->search_related( 'cds' )->count, 1, 'Still one cd');
51 $cd = $genre->find_related ('cds', {});
53 { map { $_, $cd->get_column ($_) } qw/artist year title/ },
55 artist => $artist->id,
57 title => 'the best thing since sliced bread',
59 'CD year column updated correctly',
63 # expect a create, after a failed search using *only* the
64 # *current* relationship and the unique column constraints
67 $schema->storage->debugcb(sub { push @sql, $_[1] });
68 $schema->storage->debug (1);
70 $genre->update_or_create_related ('cds', {
71 title => 'the best thing since vertical toasters',
76 $schema->storage->debugcb(undef);
80 'SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track
82 WHERE ( me.artist = ? AND me.title = ? AND me.genreid = ? )
84 'expected select issued',
87 # a has_many search without a unique constraint makes no sense
88 # but I am not sure what to test for - leaving open