From d252b39a6e818beac9e04f8aefe48e3b34798a8d Mon Sep 17 00:00:00 2001 From: vabenil Date: Sat, 5 Nov 2022 14:17:47 +0200 Subject: [PATCH] Improve one_to_many example --- database_generation.d | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/database_generation.d b/database_generation.d index 5ba8c61..1cb86fb 100644 --- a/database_generation.d +++ b/database_generation.d @@ -833,19 +833,24 @@ string toFieldName(T)(string s, bool isPlural = false) } /++ - generates get functions for a one-to-many relationship + generates get functions for a one-to-many relationship with the form + `T2 get_(T1 row, Database db)` and + `TabResultSet!T1 get_(T2 row, Database db)` + Example: ```d Struct Role { int id; } struct User { @ForeignKey!(Role.id, "") int role_id; } - mixin(one_to_many!(User.role_id), "role", "users"); - /* - this will generate the following functions - Role get_role(User role, Database db) {...} - TabResultSet!User get_users(Role row, Database db) {...} - */ + mixin(one_to_many!(User.role_id, "role", "users")); + void main() + { + Database db = ... + User user = db.find!User(1); + Role role = user.get_role(db); + auto users = role.get_users(db); + } ``` if t2 or t1 are set as null they will be infered from either the `DBName` attribute or from the name of the the Table