From ffb5fb60ed3e8c5aeb534d60bf81bde80f309484 Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Fri, 31 Jan 2020 00:54:27 -0300 Subject: [PATCH] Bug 24440: (follow-up) Make related objects prefetchable This patch creates aliases for the relations used to retrieve the linked objects from other tables. It makes the accessor names match the used relation name, for consistency. This is important for code trying to be smart and guessing what needs to be prefetched, like the API code. To test: 1. Run: $ kshell k$ prove t/db_dependent/Koha/Acquisition/Order.t => SUCCESS: Tests pass 2. Apply this patch 3. Repeat (1) => SUCCESS: Tests pass! No behaviour change 4. Verify the POD changes make sense 5. Sign off :-D Signed-off-by: Tomas Cohen Arazi Signed-off-by: David Nind Signed-off-by: Jonathan Druart Signed-off-by: Martin Renvoize --- Koha/Acquisition/Order.pm | 30 +++++++++++++++--------- Koha/Schema/Result/Aqorder.pm | 43 +++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/Koha/Acquisition/Order.pm b/Koha/Acquisition/Order.pm index 0eb5c7f3fa..55d720fcc4 100644 --- a/Koha/Acquisition/Order.pm +++ b/Koha/Acquisition/Order.pm @@ -113,43 +113,48 @@ sub add_item { =head3 basket - my $basket = Koha::Acquisition::Orders->find( $id )->basket; + my $basket = $order->basket; -Returns the basket associated to the order. +Returns the I object for the basket associated +to the order. =cut sub basket { my ( $self ) = @_; - my $basket_rs = $self->_result->basketno; + my $basket_rs = $self->_result->basket; return Koha::Acquisition::Basket->_new_from_dbic( $basket_rs ); } =head3 fund - my $fund = $order->fund + my $fund = $order->fund; -Returns the fund (aqbudgets) associated to the order. +Returns the I object for the fund (aqbudgets) +associated to the order. =cut sub fund { my ( $self ) = @_; - my $fund_rs = $self->_result->budget; + my $fund_rs = $self->_result->fund; return Koha::Acquisition::Fund->_new_from_dbic( $fund_rs ); } =head3 invoice - my $invoice = $order->invoice + my $invoice = $order->invoice; -Returns the invoice associated to the order. +Returns the I object for the invoice associated +to the order. + +It returns B if no linked invoice is found. =cut sub invoice { my ( $self ) = @_; - my $invoice_rs = $self->_result->invoiceid; + my $invoice_rs = $self->_result->invoice; return unless $invoice_rs; return Koha::Acquisition::Invoice->_new_from_dbic( $invoice_rs ); } @@ -158,13 +163,16 @@ sub invoice { my $subscription = $order->subscription -Returns the subscription associated to the order. +Returns the I object for the subscription associated +to the order. + +It returns B if no linked subscription is found. =cut sub subscription { my ( $self ) = @_; - my $subscription_rs = $self->_result->subscriptionid; + my $subscription_rs = $self->_result->subscription; return unless $subscription_rs; return Koha::Subscription->_new_from_dbic( $subscription_rs ); } diff --git a/Koha/Schema/Result/Aqorder.pm b/Koha/Schema/Result/Aqorder.pm index f9f307ceb2..a6ab12cf6a 100644 --- a/Koha/Schema/Result/Aqorder.pm +++ b/Koha/Schema/Result/Aqorder.pm @@ -664,6 +664,18 @@ __PACKAGE__->many_to_many("borrowernumbers", "aqorder_users", "borrowernumber"); # Created by DBIx::Class::Schema::Loader v0.07042 @ 2018-08-31 11:51:37 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:GQEXetlivZm7buQohl8m4A +__PACKAGE__->belongs_to( + "basket", + "Koha::Schema::Result::Aqbasket", + { "foreign.basketno" => "self.basketno" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + __PACKAGE__->belongs_to( "biblio", "Koha::Schema::Result::Biblio", @@ -676,6 +688,37 @@ __PACKAGE__->belongs_to( }, ); +__PACKAGE__->belongs_to( + "fund", + "Koha::Schema::Result::Aqbudget", + { "foreign.budget_id" => "self.budget_id" }, + { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }, +); + +__PACKAGE__->belongs_to( + "invoice", + "Koha::Schema::Result::Aqinvoice", + { "foreign.invoiceid" => "self.invoiceid" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "SET NULL", + on_update => "CASCADE", + }, +); + +__PACKAGE__->belongs_to( + "subscription", + "Koha::Schema::Result::Subscription", + { "foreign.subscriptionid" => "self.subscriptionid" }, + { + is_deferrable => 1, + join_type => "LEFT", + on_delete => "CASCADE", + on_update => "CASCADE", + }, +); + sub koha_objects_class { 'Koha::Acquisition::Orders'; } -- 2.39.5