Bug 29495: Add code level constraint replacement

This patch adds a check in Koha::Checkouts::ReturnClaim::store to
replace the database level foreign key check.

Signed-off-by: Andrew Fuerste-Henry <andrew@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Martin Renvoize 2021-11-17 10:27:38 +00:00 committed by Fridolin Somers
parent c2773d89f5
commit c5d48ed278
1 changed files with 10 additions and 0 deletions

View File

@ -53,6 +53,16 @@ sub store {
Koha::Exceptions::Checkouts::ReturnClaims::NoCreatedBy->throw();
}
unless ( !$self->issue_id
|| Koha::Checkouts->find( $self->issue_id )
|| Koha::Old::Checkouts->find( $self->issue_id ) )
{
Koha::Exceptions::Object::FKConstraint->throw(
error => 'Broken FK constraint',
broken_fk => 'issue_id'
);
}
return $self->SUPER::store;
}