Bug 30848: Fix issue exposed by unit tests

This patch changes the 'map' to a simple for loop so that we can easily
map multiple subfields to a field without overwriting the first previous
subfields in the structure.

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Martin Renvoize 2022-06-13 14:26:33 +01:00 committed by Tomas Cohen Arazi
parent 6b04e3e18f
commit 6c381c4b22
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F

View file

@ -114,14 +114,8 @@ sub _getCodedFields {
my $cached = $cache->get_from_cache( $cache_key, { unsafe => 1 } );
return $cached if $cached;
my $coded_fields = {
map {
$_->tagfield => {
$_->tagsubfield => {
'authorised_value' => $_->authorised_value
}
}
} Koha::MarcSubfieldStructures->search(
my $coded_fields = {};
my @fields = Koha::MarcSubfieldStructures->search(
{
frameworkcode => $frameworkcode,
authorised_value => { '>' => '' }
@ -130,8 +124,10 @@ sub _getCodedFields {
columns => [ 'tagfield', 'tagsubfield', 'authorised_value' ],
order_by => [ 'tagfield', 'tagsubfield' ]
}
)->as_list
};
)->as_list;
for my $field (@fields) {
$coded_fields->{ $field->tagfield }->{ $field->tagsubfield }->{'authorised_value'} = $field->authorised_value;
}
$cache->set_in_cache( $cache_key, $coded_fields );
return $coded_fields;