Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f3345acc

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

  • ID f3345acc15cb39c02047ff24c626f280f638c4e8
  • Vorgänger e3a2fcd0
  • Nachfolger ea20c6e3

Hilfsmethode zum Linken von einem Record auf ein anderes

Unterschiede anzeigen:

SL/DB/Helper/LinkedRecords.pm
2 2

  
3 3
require Exporter;
4 4
our @ISA    = qw(Exporter);
5
our @EXPORT = qw(linked_records);
5
our @EXPORT = qw(linked_records link_to_record);
6 6

  
7 7
use Carp;
8 8

  
......
42 42
  return $records;
43 43
}
44 44

  
45
sub link_to_record {
46
  my $self   = shift;
47
  my $other  = shift;
48

  
49
  croak "self has no id"  unless $self->id;
50
  croak "other has no id" unless $other->id;
51

  
52
  my %params = ( from_table => SL::DB::Helpers::Mappings::get_table_for_package(ref($self)),
53
                 from_id    => $self->id,
54
                 to_table   => SL::DB::Helpers::Mappings::get_table_for_package(ref($other)),
55
                 to_id      => $other->id,
56
               );
57

  
58
  my $link = SL::DB::Manager::RecordLink->find_by(and => [ %params ]);
59
  return $link ? $link : SL::DB::RecordLink->new(%params)->save;
60
}
61

  
45 62
1;
46 63

  
47 64
__END__
......
82 99

  
83 100
Returns an array reference.
84 101

  
102
=item C<link_to_record $record>
103

  
104
Will create an entry in the table C<record_links> with the C<from>
105
side being C<$self> and the C<to> side being C<$record>. Will only
106
insert a new entry if such a link does not already exist.
107

  
108
Returns either the existing link or the newly created one as an
109
instance of C<SL::DB::RecordLink>.
110

  
85 111
=back
86 112

  
87 113
=head1 BUGS

Auch abrufbar als: Unified diff