From 88d1257a6935a30ee54775baa1044f6d787fec64 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 18 Jul 2024 17:33:37 +0100 Subject: [PATCH] Bug 37389: Working accessors --- Koha/ILL/Requests.pm | 25 +++++-------------------- Koha/REST/Plugin/Query.pm | 5 +++-- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/Koha/ILL/Requests.pm b/Koha/ILL/Requests.pm index 289ce73d97b..a8435d1b6a1 100644 --- a/Koha/ILL/Requests.pm +++ b/Koha/ILL/Requests.pm @@ -120,18 +120,11 @@ Returns a list of relation accessor names. =cut sub _build_extended_attributes_relations { - my ($self) = @_; - - my @distinct_types = Koha::ILL::Request::Attributes->_resultset->search( - {}, # No specific conditions - { - select => ['type'], - group_by => ['type'] - } - )->get_column('type')->all; + my ( $self, $types ) = @_; - for my $type (@distinct_types) { - my $test = $self->_resultset->_result_class->has_many( + my $result_source = $self->_resultset->result_source; + for my $type ( @{$types} ) { + $result_source->add_relationship( "extended_attributes_$type", "Koha::Schema::Result::Illrequestattribute", sub { @@ -145,16 +138,8 @@ sub _build_extended_attributes_relations { { cascade_copy => 0, cascade_delete => 0 }, ); - my $schema = $self->_resultset->result_source->schema; - - $schema->unregister_source('Koha::Schema::Result::Illrequest'); - $schema->register_class( 'Koha::Schema::Result::Illrequest', $test ); - - # Testing to check if the dynamically added method has been aded. It's not been!! - $self->find(1)->extended_attributes_article_title; } - - return map { 'extended_attributes_'.$_ } @distinct_types; + return map { 'extended_attributes_' . $_ } @{$types}; } =head3 _type diff --git a/Koha/REST/Plugin/Query.pm b/Koha/REST/Plugin/Query.pm index 1c80323d4a7..2c4364cc91f 100644 --- a/Koha/REST/Plugin/Query.pm +++ b/Koha/REST/Plugin/Query.pm @@ -181,11 +181,12 @@ Generates the DBIC join attribute based on extended_attributes query entries, an { # my $ea_entries = $self->_get_extended_attributes_entries( $filtered_params, 0 ); + my @types = qw( article_title issue volume ); + # Calling our private method to build the extended attributes relations - $result_set->_build_extended_attributes_relations(); + my @test = $result_set->_build_extended_attributes_relations(\@types); # Testing out the extended attributes join (hardcoded for now) - my @test = qw( extended_attributes_article_title extended_attributes_issue extended_attributes_volume ); foreach my $test (@test) { push( @{ $attributes->{join} }, $test ); } -- 2.45.2