Bugzilla – Attachment 186461 Details for
Bug 40808
Consider a link table for accountlines to varying other Koha tables
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 40808: Add schema relationships for polymorphic account line linking
Bug-40808-Add-schema-relationships-for-polymorphic.patch (text/plain), 4.14 KB, created by
Martin Renvoize (ashimema)
on 2025-09-16 09:15:20 UTC
(
hide
)
Description:
Bug 40808: Add schema relationships for polymorphic account line linking
Filename:
MIME Type:
Creator:
Martin Renvoize (ashimema)
Created:
2025-09-16 09:15:20 UTC
Size:
4.14 KB
patch
obsolete
>From 357be6749f082363248515e896281553e9c14154 Mon Sep 17 00:00:00 2001 >From: Martin Renvoize <martin.renvoize@openfifth.co.uk> >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 | 50 +++++++++++++-------------- > Koha/Schema/Result/Reserve.pm | 13 +++++++ > 2 files changed, 38 insertions(+), 25 deletions(-) > >diff --git a/Koha/Schema/Result/AccountlineLink.pm b/Koha/Schema/Result/AccountlineLink.pm >index bc18dbca6f8..2d57e8fa4d6 100644 >--- a/Koha/Schema/Result/AccountlineLink.pm >+++ b/Koha/Schema/Result/AccountlineLink.pm >@@ -43,7 +43,7 @@ foreign key to accountlines.accountlines_id > is_nullable: 0 > size: 32 > >-Type of linked entity: hold, old_hold, checkout, old_checkout, article_request, etc. >+Type of linked entity: hold, checkout, article_request, etc. > > =head2 linked_id > >@@ -143,9 +143,22 @@ This is a polymorphic relationship. > sub linked_object { > my ($self) = @_; > >+ # Special handling for holds - they can be in reserves OR old_reserves >+ if ($self->link_type eq 'hold') { >+ # Try current holds first >+ my $hold = $self->result_source->schema->resultset('Reserve')->find({ >+ reserve_id => $self->linked_id >+ }); >+ return $hold if $hold; >+ >+ # If not found in current holds, try old holds >+ return $self->result_source->schema->resultset('OldReserve')->find({ >+ reserve_id => $self->linked_id >+ }); >+ } >+ >+ # Handle other link types normally > my $type_map = { >- 'hold' => ['Reserve', 'reserve_id'], >- 'old_hold' => ['OldReserve', 'reserve_id'], > 'checkout' => ['Issue', 'issue_id'], > 'old_checkout' => ['OldIssue', 'issue_id'], > 'article_request' => ['ArticleRequest', 'id'], >@@ -159,38 +172,25 @@ sub linked_object { > }); > } > >-=head2 linked_object_class >+=head2 koha_objects_class > >-Returns the Koha::Object class name for the linked object >+Missing POD for koha_objects_class. > > =cut > >-sub linked_object_class { >- my ($self) = @_; >- >- my $class_map = { >- 'hold' => 'Koha::Hold', >- 'old_hold' => 'Koha::Old::Hold', >- 'checkout' => 'Koha::Checkout', >- 'old_checkout' => 'Koha::Old::Checkout', >- 'article_request' => 'Koha::ArticleRequest', >- }; >- >- return $class_map->{$self->link_type}; >+sub koha_objects_class { >+ 'Koha::Account::Links'; > } > >-=head2 validate_link_integrity >+=head2 koha_object_class > >-Validates that the linked entity actually exists >+Missing POD for koha_object_class. > > =cut > >-sub validate_link_integrity { >- my ($self) = @_; >- >- my $linked_object = $self->linked_object; >- return defined($linked_object) ? 1 : 0; >+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
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 40808
:
186436
|
186437
|
186438
|
186439
|
186440
|
186441
|
186442
|
186443
|
186458
|
186459
|
186460
| 186461 |
186462
|
186463
|
186464
|
186465