mirror of https://github.com/adamdruppe/arsd.git
Merge pull request #344 from vabenil/one_to_many_handle_empty_str
One to many handle empty str
This commit is contained in:
commit
06a6a62b27
|
@ -920,15 +920,15 @@ string toFieldName(T)(string s, bool isPlural = false)
|
||||||
}
|
}
|
||||||
---
|
---
|
||||||
|
|
||||||
if t2 or t1 are set as null they will be inferred from either
|
if t2 or t1 are set as "" the get function will not be generated
|
||||||
the `DBName` attribute or from the name of the Table
|
(the name will not be inferred), if set as null they will be inferred from
|
||||||
|
either the `DBName` attribute or from the name of the Table.
|
||||||
|
|
||||||
History:
|
History:
|
||||||
Added November 5, 2022 (dub v10.10)
|
Added November 5, 2022 (dub v10.10)
|
||||||
+/
|
+/
|
||||||
template one_to_many(alias fk_field, string t2 = null, string t1 = null)
|
template one_to_many(alias fk_field, string t2 = null, string t1 = null)
|
||||||
{
|
{
|
||||||
private {
|
|
||||||
alias T1 = __traits(parent, fk_field);
|
alias T1 = __traits(parent, fk_field);
|
||||||
|
|
||||||
static assert(
|
static assert(
|
||||||
|
@ -941,9 +941,8 @@ template one_to_many(alias fk_field, string t2 = null, string t1 = null)
|
||||||
|
|
||||||
immutable string t2_name = toFieldName!T2(t2);
|
immutable string t2_name = toFieldName!T2(t2);
|
||||||
immutable string t1_name = toFieldName!T1(t1, true);
|
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)
|
T2.stringof~` get_`~t2_name~`(`~T1.stringof~` row, Database db)
|
||||||
{
|
{
|
||||||
import std.exception;
|
import std.exception;
|
||||||
|
@ -957,7 +956,8 @@ template one_to_many(alias fk_field, string t2 = null, string t1 = null)
|
||||||
).to_table_rows!`~T2.stringof~`;
|
).to_table_rows!`~T2.stringof~`;
|
||||||
|
|
||||||
return res.front();
|
return res.front();
|
||||||
}
|
}`;
|
||||||
|
static immutable string many = (t1 is "") ? "" : `
|
||||||
TabResultSet!`~T1.stringof~` get_`~t1_name~`(`~T2.stringof~` row, Database db)
|
TabResultSet!`~T1.stringof~` get_`~t1_name~`(`~T2.stringof~` row, Database db)
|
||||||
{
|
{
|
||||||
import std.exception;
|
import std.exception;
|
||||||
|
@ -972,4 +972,5 @@ template one_to_many(alias fk_field, string t2 = null, string t1 = null)
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}`;
|
}`;
|
||||||
|
static immutable string one_to_many = one ~ many;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue