Open Yaraslaut opened 3 weeks ago
Oh nice, i'm absolutely open to this. But I am pretty sure I had these cass and they compiled, hmm... :thinking:
edit: wouldn't it make more sense to name it something like HasMany<A,Through<B>>
then?
Yes, indeed, associations will be much more clear in a such way, and look similar to ruby's
I tried to implement HasMany<A,Through<B>>
and find out that c++ does not allow mixing types and non-types template argument inside variadic templates, the closest I could get is to wrap them inside structure to have
HasMany<Record<A, "a">, Record<Through<B>, "b">> records;
HasMany<Record<A, "a">> as;
Ok, so here is how to deduce variadic with types/literals using reflection https://godbolt.org/z/145M3143G
NB: With the draft-PR on static reflection, we have to adapt the way of how associations work anyways. It seems like we're moving away from the Active Record model towards Data Mapper model in order to satisfy some requirements of C++20, to get static reflection in early (i.e. the Record type must be an aggregate, i.e., we can't use inheritance nor private membmers, just plain structs without any constructor. Plus side is: modeling the SQL tables into structs becomes way more natural)
EDIT: We should still persure something like HasManyThrough<A,Through<B>>
with that. :)
https://godbolt.org/z/KPYaTcEds
I think it might be good to have following syntax for complex associations
And
HasManyThrough<A,B> records;
will fail to compile