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
Support association using join table such as Many to Many #104
Comments
hello @Fs02, can you assign me for |
Thanks, glad to have some help as well 😄 |
@bickyeric do you have any thought with the current design? The current design might look similar with activerecord has many through and has_one_through, but it's not since it's not required to have the intermediary association defined inside the struct. I'm thinking maybe we should follow this pattern? Another consideration of why the above pattern is better because it's still provide a way to update the association when the parent is saved through a table that properly defined inside our code (not just a ghost join table). I've also decided to disable autosave feature for has many through association, since it's just to much magic and it's difficult to provide one consistent and predictable behavior for all association type. and I think it's better disable autosave association by default and enabled it explicitly when needed using struct tag, and this structtag will not be supported for has many/one through. Edit: See Idea 2 |
@Fs02 I have a struggle implementing Idea 2 on how to decide which field on intermediary struct that is used to reference the association but I confused with self reference association, for Followers association we will use |
@bickyeric after looking back to the design, you are right, the problem is we cannot infer which field inside the immediate table we should use to point to the next association. Therefore, I've updated the design, now all the association has to be fully defined, and it will trigger two implicit preload, after that the result will be flattened and mapped to final assoc. let me know if it still confusing? |
Would like to add my +1 for this feature. |
Idea 2
Example
Specifications
through
and doesn't support nested through.through
tag, the second one is association insidethrough
field that has the singular name as has through field. The result then flattened and mapped to the final association.Merit/Demerit
(+) Support has one and has many through
(+) Can be made read only and still accessible for update.
(+) We can have metadata on join table.
(-) Require additional association defined (especially verbose for self referencing association).
Idea 1Example:
Specifications
through
.subscription:id <- subscription_id:subscription_users:user_id -> user:id
is declared as:
ref:"id:subscription_id" fk:"id:user_id" through:"subscription_users"
Insert/Update supportEdit: to complex and to magic to implementMerit/Demerit
(+) Can implement many to many without additional struct.
(-) Doesn't work for has one through.
(-) Can't be made fully readonly(can update but only the join data).
The text was updated successfully, but these errors were encountered: