+sub link_to_record {
+ my $self = shift;
+ my $other = shift;
+
+ croak "self has no id" unless $self->id;
+ croak "other has no id" unless $other->id;
+
+ my %params = ( from_table => SL::DB::Helpers::Mappings::get_table_for_package(ref($self)),
+ from_id => $self->id,
+ to_table => SL::DB::Helpers::Mappings::get_table_for_package(ref($other)),
+ to_id => $other->id,
+ );
+
+ my $link = SL::DB::Manager::RecordLink->find_by(and => [ %params ]);
+ return $link ? $link : SL::DB::RecordLink->new(%params)->save;
+}
+