From 78405205ae7f61260c2c6320be430dff73d2e646 Mon Sep 17 00:00:00 2001 From: Lukas Mueller Date: Sun, 11 Dec 2022 17:14:31 -0500 Subject: [PATCH] add a synonyms() accessor (with lazy loading). --- lib/CXGN/Stock.pm | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/lib/CXGN/Stock.pm b/lib/CXGN/Stock.pm index 69acaef8b..145244308 100644 --- a/lib/CXGN/Stock.pm +++ b/lib/CXGN/Stock.pm @@ -479,6 +479,26 @@ has 'subjects' => ( is => 'rw', ); +=head2 accessor synonyms() + + Usage: my $synonyms = $stock->synonyms(); + Desc: retrieves synonyms from the database as a lazy build + Ret: listref of synonyms + Args: + Side Effects: accesses the database + Example: + +=cut + +has 'synonyms' => ( + isa => 'Maybe[Ref]', + is => 'rw', + lazy => 1, + builder => '_retrieve_synonyms', +); + + + sub BUILD { my $self = shift; @@ -547,6 +567,20 @@ sub _retrieve_stock_owner { $self->owners(\@owners); } +sub _retrieve_synonyms { + my $self =shift; + if (! $self->stock_id()) { + return []; + } + my $synonym_type_id = SGN::Model::Cvterm->get_cvterm_row($self->schema(), 'stock_synonym', 'stock_property')->cvterm_id(); + my $synonyms_rs = $self->schema()->resultset("Stock::Stockprop")->search( { stock_id => $self->stock_id(), type_id => $synonym_type_id }); + my @synonyms = (); + while (my $row = $synonyms_rs->next()) { + push @synonyms, $row->value(); + } + return \@synonyms; +} + =head2 store() Usage: $self->store @@ -1533,6 +1567,11 @@ sub add_synonym { $stock->create_stockprops({$synonym_cvterm->name() => $synonym}); } +=head2 synonyms() + + Usage: @synonyms = $stock->synonyms(); + Desc: retrieves the synonyms as a list + =head2 merge() -- 2.11.4.GIT