From 62c0e125318dc2c67bfaf37c654c51d4c8fb5ff4 Mon Sep 17 00:00:00 2001 From: Dave Roberts Date: Fri, 8 Nov 2024 11:26:00 +0000 Subject: [PATCH] Fixed error in search by people field --- lib/GADS/Column/Person.pm | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/lib/GADS/Column/Person.pm b/lib/GADS/Column/Person.pm index 1a7b710cf..07ade7bcd 100644 --- a/lib/GADS/Column/Person.pm +++ b/lib/GADS/Column/Person.pm @@ -211,4 +211,45 @@ sub import_value }); } +sub values_beginning_with +{ my ($self, $match_string, %options) = @_; + + my $resultset = $self->resultset_for_values; + my @value; + my $value_field = 'me.'.$self->value_field; + $match_string =~ s/([_%])/\\$1/g; + my $search = $match_string + ? { + $value_field => { + -like => "${match_string}%", + }, + } + : $options{noempty} && !$match_string + ? { \"0 = 1" } # Nothing to match, return nothing + : {}; + if ($resultset) { + my $match_result = $resultset->search($search, + { + rows => 10, + }, + ); + @value = map { + { + id => $_->get_column('id'), + label => $_->get_column($self->value_field), + } + } $match_result->search({}, { + select => [ + { + max => 'me.id', + -as => 'id', + }, + $value_field + ], + group_by => [ $value_field, 'me.surname', 'me.firstname' ], + })->all; + } + return @value; +} + 1;