adamdruppe / arsd

This is a collection of modules that I've released over the years. Most of them stand alone, or have just one or two dependencies in here, so you don't have to download this whole repo.
http://arsd-official.dpldocs.info/arsd.html
530 stars 125 forks source link

One to many handle empty str #344

Closed vabenil closed 1 year ago

vabenil commented 1 year ago

Handle when "" is passed to t1 or t2. Currently if "" gets passed to t1 or t2 it will just result in a compilation error. This pr handles that case by not generating the respective function if t1 or t2 is left empty. Example

struct Role { int id; }

struct User {
    int id;
    @ForeignKey!(Role.id, "") int role_id;
}

mixin(one_to_many(User.role_id, "role", ""));
Database db = ...
User user = ...
Role role = user.get_role(db); // Works
auto users = role.get_users(db); // Error get_users doesn't exist

EDIT: fix example