my $schema = DBICTest->init_schema();
-plan tests => 34;
+plan tests => 39;
+
+# Check the defined unique constraints
+is_deeply(
+ [ sort $schema->source('CD')->unique_constraint_names ],
+ [ qw/cd_artist_title primary/ ],
+ 'CD source has an automatically named unique constraint'
+);
+is_deeply(
+ [ sort $schema->source('Producer')->unique_constraint_names ],
+ [ qw/primary prod_name/ ],
+ 'Producer source has a named unique constraint'
+);
+is_deeply(
+ [ sort $schema->source('Track')->unique_constraint_names ],
+ [ qw/primary track_cd_position track_cd_title/ ],
+ 'Track source has three unique constraints'
+);
my $artistid = 1;
my $title = 'UNIQUE Constraint';
artist => $artistid,
title => $title,
},
- { key => 'artist_title' }
+ { key => 'cd_artist_title' }
);
is($cd2->get_column('artist'), $cd1->get_column('artist'), 'find by specific key: artist is correct');
is($cd2->title, $cd1->title, 'title is correct');
is($cd2->year, $cd1->year, 'year is correct');
-my $cd3 = $schema->resultset('CD')->find($artistid, $title, { key => 'artist_title' });
+my $cd3 = $schema->resultset('CD')->find($artistid, $title, { key => 'cd_artist_title' });
is($cd3->get_column('artist'), $cd1->get_column('artist'), 'find by specific key, ordered columns: artist is correct');
is($cd3->title, $cd1->title, 'title is correct');
title => $title,
year => 2007,
},
- { key => 'artist_title' }
+ { key => 'cd_artist_title' }
);
ok(! $cd5->is_changed, 'update_or_create by specific key: row is clean');
title => $title,
year => 2010,
},
- { key => 'artist_title' }
+ { key => 'cd_artist_title' }
);
is($cd7->cdid, $cd1->cdid, 'find_or_create by specific key: cdid is correct');
my $artist = $schema->resultset('Artist')->find($artistid);
my $cd8 = $artist->find_or_create_related('cds',
{
- artist => $artistid,
title => $title,
year => 2020,
},
- { key => 'artist_title' }
+ { key => 'cd_artist_title' }
);
is($cd8->cdid, $cd1->cdid, 'find_or_create related by specific key: cdid is correct');
my $cd9 = $artist->update_or_create_related('cds',
{
- artist => $artistid,
title => $title,
year => 2021,
},
- { key => 'artist_title' }
+ { key => 'cd_artist_title' }
);
ok(! $cd9->is_changed, 'update_or_create by specific key: row is clean');
is($cd9->title, $cd1->title, 'title is correct');
is($cd9->year, 2021, 'year is correct');
+# KNOWN TO FAIL: Table with two unique constraints, and we're satisying one of them
+my $track = $schema->resultset('Track')->find(
+ {
+ cd => 1,
+ position => 3,
+ },
+ { order_by => 'position' }
+);
+
+is($track->get_column('cd'), 1, 'track cd is correct');
+is($track->get_column('position'), 3, 'track position is correct');