Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template arguments for associations #45

Open
Yaraslaut opened this issue Sep 23, 2024 · 5 comments
Open

Template arguments for associations #45

Yaraslaut opened this issue Sep 23, 2024 · 5 comments

Comments

@Yaraslaut
Copy link
Member

https://godbolt.org/z/KPYaTcEds

I think it might be good to have following syntax for complex associations

class A{};
class B{};

class Something{
    HasManyThrough<A,Through<B>> records;
};

And HasManyThrough<A,B> records; will fail to compile

@christianparpart
Copy link
Member

christianparpart commented Sep 25, 2024

Oh nice, i'm absolutely open to this. But I am pretty sure I had these cass and they compiled, hmm... 🤔

edit: wouldn't it make more sense to name it something like HasMany<A,Through<B>> then?

@Yaraslaut
Copy link
Member Author

Yes, indeed, associations will be much more clear in a such way, and look similar to ruby's

@Yaraslaut
Copy link
Member Author

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;

https://godbolt.org/z/5MvGW3boK

@Yaraslaut
Copy link
Member Author

Ok, so here is how to deduce variadic with types/literals using reflection
https://godbolt.org/z/145M3143G

@christianparpart
Copy link
Member

christianparpart commented Oct 15, 2024

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. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants