diff --git a/lib/App/Netdisco/DB/ResultSet/Node.pm b/lib/App/Netdisco/DB/ResultSet/Node.pm index adc6027a..2550fe4e 100644 --- a/lib/App/Netdisco/DB/ResultSet/Node.pm +++ b/lib/App/Netdisco/DB/ResultSet/Node.pm @@ -121,25 +121,27 @@ sub delete { # for node_ip only delete if there are no longer # any nodes referencing the IP. - my $except = $nodes->search(undef, { '+columns' => 'port' })->as_query; - my @except_all = @{$$except}; - my $except_query = shift @except_all; + + my @mac_restrict_aq = @{${ $nodes->as_query }}; + my @macport_restrict_aq = @{${ $nodes->search(undef, { '+columns' => 'port' })->as_query }}; + my $mac_restrict = shift @mac_restrict_aq; + my $macport_restrict = shift @macport_restrict_aq; my $deleted = $schema->storage->dbh_do(sub { my ($storage, $dbh, @extra) = @_; - local $dbh->{TraceLevel} = '1|SQL'; + local $dbh->{TraceLevel} = + ($ENV{DBIC_TRACE} ? '1|SQL' : $dbh->{TraceLevel}); $dbh->do(<[1]} @except_all)); + , undef, (map {$_->[1]} (@macport_restrict_aq, @mac_restrict_aq))); }); # now let DBIC do its thing