From fa436a5bad718d3b6022f3ce4b43359903e3f7c9 Mon Sep 17 00:00:00 2001 From: Pedro Amorim Date: Fri, 26 Jul 2024 14:24:44 +0000 Subject: [PATCH] Bug 35287: Follow-up 37389: ExtendedAttributes Apply ExtendedAttributes Mixin to AdditionalFields To test the ExtendedAttributes mixin search is working: 1) Create 2 or more searchable licenses additional fields 2) Create a new license and enter values in these searchable fields 3) Go to the licenses list, use the column filters to search on more than one column, verify that the search work as intended (AND operator) --- Koha/ERM/Licenses.pm | 2 +- Koha/Objects/Mixin/AdditionalFields.pm | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Koha/ERM/Licenses.pm b/Koha/ERM/Licenses.pm index b1619ee63c..abece2c679 100644 --- a/Koha/ERM/Licenses.pm +++ b/Koha/ERM/Licenses.pm @@ -22,7 +22,7 @@ use Koha::Database; use Koha::ERM::License; -use base qw(Koha::Objects Koha::Objects::Mixin::AdditionalFields); +use base qw(Koha::Objects::Mixin::AdditionalFields Koha::Objects); =head1 NAME diff --git a/Koha/Objects/Mixin/AdditionalFields.pm b/Koha/Objects/Mixin/AdditionalFields.pm index a412d3215a..8351aba549 100644 --- a/Koha/Objects/Mixin/AdditionalFields.pm +++ b/Koha/Objects/Mixin/AdditionalFields.pm @@ -2,6 +2,8 @@ package Koha::Objects::Mixin::AdditionalFields; use Modern::Perl; +use base qw(Koha::Objects::Mixin::ExtendedAttributes); + =head1 NAME Koha::Objects::Mixin::AdditionalFields @@ -56,6 +58,28 @@ 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) = @_; + + my $tablename_query = $self->extended_attributes_tablename_query; + + return { + 'id_field' => { 'foreign' => 'record_id', 'self' => $self->_resultset->result_source->primary_columns }, + 'key_field' => 'field_id', + 'schema_class' => 'Koha::Schema::Result::AdditionalFieldValue', + }; +} + +sub extended_attributes_tablename_query { + my ($self) = @_; + + return { 'tablename' => $self->_resultset->result_source->name, 'operator' => '=' }; +} + =head1 AUTHOR Koha Development Team -- 2.39.2