# Some attributes when present require a subquery
# This might not work on some database (mysql), but...
# it won't work without the subquery either so who cares
- if (grep { defined $self->{attrs}{$_} } qw/join rows group_by/) {
+ if (grep { defined $self->{attrs}{$_} } qw/seen_join from rows group_by/) {
foreach my $pk ($self->result_source->primary_columns) {
$cond->{$pk} = { IN => $self->get_column($pk)->as_query };
my $cdrs = $schema->resultset('CD');
# create some custom entries
-$ars->create ({ artistid => 9, name => 'dead man walking' });
+$ars->populate ([
+ [qw/artistid name/],
+ [qw/71 a1/],
+ [qw/72 a2/],
+ [qw/73 a3/],
+]);
$cdrs->populate ([
[qw/cdid artist title year/],
- [qw/70 2 delete0 2005/],
- [qw/71 3 delete1 2005/],
- [qw/72 3 delete2 2005/],
- [qw/73 3 delete3 2006/],
- [qw/74 3 delete4 2007/],
- [qw/75 9 delete5 2008/],
+ [qw/70 71 delete0 2005/],
+ [qw/71 72 delete1 2005/],
+ [qw/72 72 delete2 2005/],
+ [qw/73 72 delete3 2006/],
+ [qw/74 72 delete4 2007/],
+ [qw/75 73 delete5 2008/],
]);
my $total_cds = $cdrs->count;
# test that delete_related w/o conditions deletes all related records only
-$ars->find (9)->delete_related ('cds');
+$ars->search ({name => 'a3' })->search_related ('cds')->delete;
is ($cdrs->count, $total_cds -= 1, 'related delete ok');
-my $a3_cds = $ars->find(3)->cds;
+my $a2_cds = $ars->search ({ name => 'a2' })->search_related ('cds');
# test that related deletion w/conditions deletes just the matched related records only
-$a3_cds->search ({ year => 2005 })->delete;
+$a2_cds->search ({ year => 2005 })->delete;
is ($cdrs->count, $total_cds -= 2, 'related + condition delete ok');
# test that related deletion with limit condition works
-$a3_cds->search ({}, { rows => 1})->delete;
+$a2_cds->search ({}, { rows => 1})->delete;
is ($cdrs->count, $total_cds -= 1, 'related + limit delete ok');