skipover now implicit from deferrals/actionset; fix sql where logic with better correlation

This commit is contained in:
Oliver Gorwits
2017-05-23 17:27:43 +01:00
parent b51edbccd2
commit 4550b8a84c
5 changed files with 40 additions and 17 deletions

View File

@@ -58,21 +58,29 @@ __PACKAGE__->set_primary_key("job");
=head1 RELATIONSHIPS
=head2 skipped
=head2 device_skips( $backend?, $max_deferrals? )
Retuns the set of C<device_skip> entries which may apply to this job. They
match the device IP and job action, and may refer to one or more backends.
Retuns the set of C<device_skip> entries which apply to this job. They match
the device IP, current backend, and job action.
You probably want to use the ResultSet method C<skipped> which completes this
query with a C<backend> host and C<max_deferrals> parameters (or sensible
defaults).
=cut
__PACKAGE__->has_many( skipped => 'App::Netdisco::DB::Result::DeviceSkip',
__PACKAGE__->has_many( device_skips => 'App::Netdisco::DB::Result::DeviceSkip',
sub {
my $args = shift;
return {
"$args->{foreign_alias}.backend" => { '=' => \'?' },
"$args->{foreign_alias}.device"
=> { -ident => "$args->{self_alias}.device" },
"$args->{foreign_alias}.actionset"
=> { '@>' => \"string_to_array($args->{self_alias}.action,'')" },
-or => [
{ "$args->{foreign_alias}.actionset"
=> { '@>' => \"string_to_array($args->{self_alias}.action,'')" } },
{ "$args->{foreign_alias}.deferrals" => { '>=' => \'?' } },
],
};
},
{ cascade_copy => 0, cascade_update => 0, cascade_delete => 0 }