From d2ca1c8631d51c2493946d226a6c1ee65e4420ed Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Mon, 15 Sep 2025 13:26:46 +0100 Subject: [PATCH] Bug 40808: Add schema relationships for polymorphic account line linking Adds the necessary DBIx::Class relationships to support polymorphic linking between account lines and various entities: 1. Koha::Schema::Result::Reserve - Adds accountline_links relationship to enable holds to find their linked account lines 2. Koha::Schema::Result::AccountlineLink - Enhanced polymorphic methods for accessing linked objects and validation These relationships enable proper traversal from holds to account lines and support the polymorphic linking system. --- Koha/Schema/Result/AccountlineLink.pm | 22 +++++++++++++++++++++- Koha/Schema/Result/Reserve.pm | 13 +++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/Koha/Schema/Result/AccountlineLink.pm b/Koha/Schema/Result/AccountlineLink.pm index bc18dbca6f8..4b2627b4796 100644 --- a/Koha/Schema/Result/AccountlineLink.pm +++ b/Koha/Schema/Result/AccountlineLink.pm @@ -192,5 +192,25 @@ sub validate_link_integrity { return defined($linked_object) ? 1 : 0; } +=head2 koha_objects_class + +Missing POD for koha_objects_class. + +=cut + +sub koha_objects_class { + 'Koha::Account::Links'; +} + +=head2 koha_object_class + +Missing POD for koha_object_class. + +=cut + +sub koha_object_class { + 'Koha::Account::Link'; +} + # You can replace this text with custom code or comments, and it will be preserved on regeneration -1; \ No newline at end of file +1; diff --git a/Koha/Schema/Result/Reserve.pm b/Koha/Schema/Result/Reserve.pm index 3e65b00f67c..ac23c2cb20e 100644 --- a/Koha/Schema/Result/Reserve.pm +++ b/Koha/Schema/Result/Reserve.pm @@ -588,4 +588,17 @@ __PACKAGE__->belongs_to( { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, ); +__PACKAGE__->has_many( + "accountline_links", + "Koha::Schema::Result::AccountlineLink", + sub { + my ($args) = @_; + return { + "$args->{foreign_alias}.link_type" => 'hold', + "$args->{foreign_alias}.linked_id" => { '=' => { -ident => "$args->{self_alias}.reserve_id" } }, + }; + }, + { cascade_copy => 0, cascade_delete => 0 }, +); + 1; -- 2.51.0