From f395f8aa0bcf0d06067feca13205be2ba6a49219 Mon Sep 17 00:00:00 2001
From: Pedro Amorim <pedro.amorim@ptfs-europe.com>
Date: Tue, 10 Dec 2024 14:43:47 +0000
Subject: [PATCH] Bug 38663: DBIC: Add AdditionalFields to Library

---
 Koha/Schema/Result/Branch.pm | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/Koha/Schema/Result/Branch.pm b/Koha/Schema/Result/Branch.pm
index c9d55a81826..aeed6695d55 100644
--- a/Koha/Schema/Result/Branch.pm
+++ b/Koha/Schema/Result/Branch.pm
@@ -999,6 +999,22 @@ __PACKAGE__->has_many(
 # Created by DBIx::Class::Schema::Loader v0.07051 @ 2024-05-03 13:13:25
 # DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:HiH1QNlDqKcq9GeM85Pu0A
 
+__PACKAGE__->has_many(
+    "additional_field_values",
+    "Koha::Schema::Result::AdditionalFieldValue",
+    sub {
+        my ($args) = @_;
+
+        return {
+            "$args->{foreign_alias}.record_id" => { -ident => "$args->{self_alias}.branchcode" },
+
+            "$args->{foreign_alias}.field_id" =>
+                { -in => \'(SELECT id FROM additional_fields WHERE tablename="branches")' },
+        };
+    },
+    { cascade_copy => 0, cascade_delete => 0 },
+);
+
 __PACKAGE__->add_columns(
     '+pickup_location' => { is_boolean => 1 },
     '+public'          => { is_boolean => 1 }
-- 
2.39.5