diff options
author | Birte Kristina Friesel <derf@finalrewind.org> | 2023-10-01 07:11:58 +0200 |
---|---|---|
committer | Birte Kristina Friesel <derf@finalrewind.org> | 2023-10-01 07:11:58 +0200 |
commit | aaeb81a5d230ca556fa950d0f9be0b98e85effcf (patch) | |
tree | df292cdded847b4a7fac78e91b9050fd13c5fcbe /lib/Travelynx/Model/Stations.pm | |
parent | 2638dd36fba1fc3389138906a7436aba311dbe54 (diff) |
store related stations; respect them when looking up connections
Diffstat (limited to 'lib/Travelynx/Model/Stations.pm')
-rw-r--r-- | lib/Travelynx/Model/Stations.pm | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/Travelynx/Model/Stations.pm b/lib/Travelynx/Model/Stations.pm index ecd8adb..147219f 100644 --- a/lib/Travelynx/Model/Stations.pm +++ b/lib/Travelynx/Model/Stations.pm @@ -50,6 +50,41 @@ sub add_or_update { ); } +sub add_meta { + my ( $self, %opt ) = @_; + my $db = $opt{db} // $self->{pg}->db; + my $eva = $opt{eva}; + my @meta = @{ $opt{meta} }; + + for my $meta (@meta) { + if ( $meta != $eva ) { + $db->insert( + 'related_stations', + { + eva => $eva, + meta => $meta + }, + { on_conflict => undef } + ); + } + } +} + +sub get_meta { + my ( $self, %opt ) = @_; + my $db = $opt{db} // $self->{pg}->db; + my $eva = $opt{eva}; + + my $res = $db->select( 'related_stations', ['meta'], { eva => $eva } ); + my @ret; + + while ( my $row = $res->hash ) { + push( @ret, $row->{meta} ); + } + + return @ret; +} + sub get_for_autocomplete { my ($self) = @_; |