From a0e2efc223f559294b360bdeacbe69d92aa8ca8e Mon Sep 17 00:00:00 2001 From: vabenil Date: Tue, 8 Nov 2022 15:12:46 +0200 Subject: [PATCH] one_to_many handle when t1 or t2 are "" --- database_generation.d | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/database_generation.d b/database_generation.d index 56bf564..882cf69 100644 --- a/database_generation.d +++ b/database_generation.d @@ -941,7 +941,7 @@ template one_to_many(alias fk_field, string t2 = null, string t1 = null) immutable string t2_name = toFieldName!T2(t2); immutable string t1_name = toFieldName!T1(t1, true); - static immutable string one_to_many = + static immutable string one = (t2 is "") ? "" : T2.stringof~` get_`~t2_name~`(`~T1.stringof~` row, Database db) { import std.exception; @@ -955,7 +955,8 @@ template one_to_many(alias fk_field, string t2 = null, string t1 = null) ).to_table_rows!`~T2.stringof~`; return res.front(); - } + }`; + static immutable string many = (t1 is "") ? "" : ` TabResultSet!`~T1.stringof~` get_`~t1_name~`(`~T2.stringof~` row, Database db) { import std.exception; @@ -970,4 +971,5 @@ template one_to_many(alias fk_field, string t2 = null, string t1 = null) return res; }`; + static immutable string one_to_many = one ~ many; }