From 9bcb6f26a1dac6b84ffcf4fca2481833f9feb48f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Thu, 11 Apr 2019 09:31:15 +0100 Subject: [PATCH] Bug 22683: Allow prefetch with Koha::Account::Line->checkouts This patch adds the required DBIC side relationships for the Koha::Account::Line checkouts relationship accessor to support prefetching and also updates the method to enable the capability. Signed-off-by: Martin Renvoize --- Koha/Account/Line.pm | 10 ++++--- Koha/Schema/Result/Accountline.pm | 44 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 4 deletions(-) diff --git a/Koha/Account/Line.pm b/Koha/Account/Line.pm index ef9f4f9063..4e9a6f655b 100644 --- a/Koha/Account/Line.pm +++ b/Koha/Account/Line.pm @@ -62,11 +62,13 @@ Return the checkout linked to this account line if exists sub checkout { my ( $self ) = @_; - return unless $self->issue_id ; + return unless $self->issue_id; + my $issue_rs = $self->_result->issue; + return Koha::Checkout->_new_from_dbic( $issue_rs ) if $issue_rs; - $self->{_checkout} ||= Koha::Checkouts->find( $self->issue_id ); - $self->{_checkout} ||= Koha::Old::Checkouts->find( $self->issue_id ); - return $self->{_checkout}; + my $old_issue_rs = $self->_result->old_issue; + return Koha::Old::Checkout->_new_from_dbic( $old_issue_rs ) if $old_issue_rs; + return undef; } =head3 void diff --git a/Koha/Schema/Result/Accountline.pm b/Koha/Schema/Result/Accountline.pm index aa204d4fa1..767ff1e76a 100644 --- a/Koha/Schema/Result/Accountline.pm +++ b/Koha/Schema/Result/Accountline.pm @@ -279,4 +279,48 @@ sub koha_object_class { 'Koha::Account::Line'; } +=head2 issue + +Type: belongs_to + +Related object: L + +Note: This DBIC only relationship should be removed (as it will get automatically recreated) +if we add a proper foreign key for accountlines.issue_id + +=cut + +__PACKAGE__->belongs_to( + "issue", + "Koha::Schema::Result::Issue", + { "foriegn.issue_id" => "self.issue_id" }, + { + is_deferrable => 1, + join_type => "LEFT" + }, +); + +=head2 old_issue + +Type: belongs_to + +Related object: L + +Note: This DBIC only relationship should be removed (as it will get automatically recreated) +if we add a proper foreign key for accountlines.issue_id + +=cut + +__PACKAGE__->belongs_to( + "old_issue", + "Koha::Schema::Result::OldIssue", + { "foriegn.issue_id" => "self.issue_id" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + 1; -- 2.20.1