From 803ad345fde382ceb66cda5db7ef99634edc055f Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Tue, 18 Jan 2022 11:29:59 +0000 Subject: [PATCH] Bug 29495: (follow-up) Fix Tests Update DBIC relation types to prevent double issue creation during object build. --- Koha/Schema/Result/ReturnClaim.pm | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/Koha/Schema/Result/ReturnClaim.pm b/Koha/Schema/Result/ReturnClaim.pm index 9e67c7f0e7..49ded3b9f9 100644 --- a/Koha/Schema/Result/ReturnClaim.pm +++ b/Koha/Schema/Result/ReturnClaim.pm @@ -282,16 +282,22 @@ __PACKAGE__->belongs_to( =head2 checkout -Type: belongs_to +Type: has_many but should be belongs_to + +To get around TestBuilder failures we set this relation to has_many as it +allows us to produce the same query without triggering TestBuilder failures +(when it tries to create the issue twice, once for the checkout and once for +the old_checkouts relation below). might_have would also be more appropriate, +but this triggers a DBIC warning as the key field here is nullable. Related object: L =cut -__PACKAGE__->belongs_to( +__PACKAGE__->has_many( "checkout", "Koha::Schema::Result::Issue", - { issue_id => "issue_id" }, + { "foreign.issue_id" => "self.issue_id" }, { is_deferrable => 1, join_type => "LEFT", @@ -300,16 +306,22 @@ __PACKAGE__->belongs_to( =head2 old_checkout -Type: belongs_to +Type: has_many but should be belongs_to + +To get around TestBuilder failures we set this relation to has_many as it +allows us to produce the same query without triggering TestBuilder failures +(when it tries to create the issue twice, once for the checkout relation above +and once for the old_checkouts). might_have would also be more appropriate, +but this triggers a DBIC warning as the key field here is nullable. Related object: L =cut -__PACKAGE__->belongs_to( +__PACKAGE__->has_many( "old_checkout", "Koha::Schema::Result::OldIssue", - { issue_id => "issue_id" }, + { "foreign.issue_id" => "self.issue_id" }, { is_deferrable => 1, join_type => "LEFT", -- 2.20.1