From c226a8522e1b35e28432ddd24d1b8540a6606729 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Mon, 22 Jul 2024 16:14:38 +0000 Subject: [PATCH] Bug 37389: Apply ExtendedAttributes Mixin to AdditionalFields This is only applied to subscription for now. More are missing --- Koha/ILL/Requests.pm | 3 ++- Koha/Object/Mixin/AdditionalFields.pm | 2 ++ Koha/Objects/Mixin/AdditionalFields.pm | 13 +++++++++++++ Koha/Objects/Mixin/ExtendedAttributes.pm | 4 ++-- Koha/Patrons.pm | 3 ++- Koha/Subscription.pm | 8 ++++++++ 6 files changed, 29 insertions(+), 4 deletions(-) diff --git a/Koha/ILL/Requests.pm b/Koha/ILL/Requests.pm index f10e6edd6f..39ca48d3e9 100644 --- a/Koha/ILL/Requests.pm +++ b/Koha/ILL/Requests.pm @@ -112,8 +112,9 @@ sub search_incomplete { =cut sub extended_attributes_config { + my ( $self ) = @_; return { - 'id_field' => 'illrequest_id', + 'id_field' => { 'foreign' => 'illrequest_id', 'self' => 'illrequest_id' }, 'key_field' => 'type', 'schema_class' => 'Koha::Schema::Result::Illrequestattribute', }; diff --git a/Koha/Object/Mixin/AdditionalFields.pm b/Koha/Object/Mixin/AdditionalFields.pm index bf6598d8c9..eaeebbde1c 100644 --- a/Koha/Object/Mixin/AdditionalFields.pm +++ b/Koha/Object/Mixin/AdditionalFields.pm @@ -4,6 +4,8 @@ use Modern::Perl; use Koha::AdditionalFields; use Koha::AdditionalFieldValues; +use base qw(Koha::Objects::Mixin::ExtendedAttributes); + =head1 NAME Koha::Object::Mixin::AdditionalFields diff --git a/Koha/Objects/Mixin/AdditionalFields.pm b/Koha/Objects/Mixin/AdditionalFields.pm index a412d3215a..a383abf865 100644 --- a/Koha/Objects/Mixin/AdditionalFields.pm +++ b/Koha/Objects/Mixin/AdditionalFields.pm @@ -56,6 +56,19 @@ sub filter_by_additional_fields { return $class->search(\%conditions, { join => [ ('additional_field_values') x $idx ] }); } +=head3 extended_attributes_config + +=cut + +sub extended_attributes_config { + my ($self) = @_; + return { + 'id_field' => { 'foreign' => 'record_id', 'self' => $self->extended_attributes_record_id_field }, + 'key_field' => 'field_id', + 'schema_class' => 'Koha::Schema::Result::AdditionalFieldValue', + }; +} + =head1 AUTHOR Koha Development Team diff --git a/Koha/Objects/Mixin/ExtendedAttributes.pm b/Koha/Objects/Mixin/ExtendedAttributes.pm index f4d4420d47..01c646af75 100644 --- a/Koha/Objects/Mixin/ExtendedAttributes.pm +++ b/Koha/Objects/Mixin/ExtendedAttributes.pm @@ -49,8 +49,8 @@ sub _build_extended_attributes_relations { my $args = shift; return { - "$args->{foreign_alias}.$ea_config->{id_field}" => - { -ident => "$args->{self_alias}.$ea_config->{id_field}" }, + "$args->{foreign_alias}.$ea_config->{id_field}->{foreign}" => + { -ident => "$args->{self_alias}.$ea_config->{id_field}->{self}" }, "$args->{foreign_alias}.$ea_config->{key_field}" => { '=', $type }, }; }, diff --git a/Koha/Patrons.pm b/Koha/Patrons.pm index 3f11d3d326..813d741c2a 100644 --- a/Koha/Patrons.pm +++ b/Koha/Patrons.pm @@ -571,8 +571,9 @@ sub filter_by_have_permission { =cut sub extended_attributes_config { + my ( $self ) = @_; return { - 'id_field' => 'borrowernumber', + 'id_field' => { 'foreign' => 'borrowernumber', 'self' => 'borrowernumber' }, 'key_field' => 'code', 'schema_class' => 'Koha::Schema::Result::BorrowerAttribute', }; diff --git a/Koha/Subscription.pm b/Koha/Subscription.pm index 45d1c09fa0..46e3485f88 100644 --- a/Koha/Subscription.pm +++ b/Koha/Subscription.pm @@ -195,6 +195,14 @@ sub get_sharable_info { } +=head3 extended_attributes_record_id_field + +=cut + +sub extended_attributes_record_id_field { + return 'subscriptionid'; +} + =head3 _type =cut -- 2.39.2