+sub get_links_via {
+ $main::lxdebug->enter_sub();
+
+ use SL::MoreCommon;
+ use Data::Dumper;
+
+ my $self = shift;
+ my %params = @_;
+
+ Common::check_params(\%params, [ qw(from_table from_id to_table to_id) ]);
+ Common::check_params(\%params, "via");
+
+ my @hops = ref $params{via} eq 'ARRAY'
+ ? @{ $params{via} }
+ : $params{via};
+ unshift @hops, +{ table => $params{from_table}, id => $params{from_id} };
+ push @hops, +{ table => $params{to_table}, id => $params{to_id} };
+
+ my $myconfig = \%main::myconfig;
+ my $form = $main::form;
+
+ my $last_hop = shift @hops;
+ my @links;
+ for my $hop (@hops) {
+
+ my @temp_links = $self->get_links(
+ from_table => $last_hop->{table},
+ from_id => $last_hop->{id},
+ to_table => $hop->{table},
+ to_id => $hop->{id},
+ );
+
+ # short circuit if any of these are empty
+ return wantarray ? () : [] unless scalar @temp_links;
+
+ push @links, \@temp_links;
+ $last_hop = $hop;
+ }
+
+ my $result = reduce {
+ [
+ grep { $_ }
+ cross {
+ if ( $a->{to_table} eq $b->{from_table}
+ && $a->{to_id} eq $b->{from_id} ) {
+ +{ from_table => $a->{from_table},
+ from_id => $a->{from_id},
+ to_table => $b->{to_table},
+ to_id => $b->{to_id} }
+ }
+ } @{ $a }, @{ $b }
+ ]
+ } @links;
+
+ $main::lxdebug->leave_sub();
+
+ return wantarray ? @{ $result } : $result;
+}
+
+sub delete {
+ $main::lxdebug->enter_sub();
+
+ my $self = shift;
+ my %params = @_;
+
+ Common::check_params(\%params, [ qw(from_table from_id to_table to_id) ]);
+
+ my $myconfig = \%main::myconfig;
+ my $form = $main::form;
+
+ SL::DB->client->with_transaction(sub {
+ my $dbh = $params{dbh} || SL::DB->client->dbh;
+
+ # content
+ my (@where_tokens, @where_values);
+
+ for my $col (qw(from_table from_id to_table to_id)) {
+ add_token(\@where_tokens, \@where_values, col => $col, val => $params{$col}) if $params{$col};
+ }
+
+ my $where = @where_tokens ? "WHERE ". join ' AND ', map { "($_)" } @where_tokens : '';
+ my $query = "DELETE FROM record_links $where";
+
+ do_query($form, $dbh, $query, @where_values);
+
+ 1;
+ }) or die { SL::DB->client->error };
+
+ $main::lxdebug->leave_sub();
+}
+