vuex-orm-next
vuex-orm-next copied to clipboard
Add Belongs To Many relation
Ref: https://vuex-orm.org/guide/model/relationships.html#many-to-many
We're loving it that vuex-orm already has a vue3 compatible branch, but yes -BelongsToMany (or many to many) would be a good addition.
Can I ask what's this feature's priority and schedule? I'm trying to use next-vuex-orm in a new project and this would be very helpful.
Sorry it's taking long 😓 Because in my use case most of the time I can just use HasManyBy for inverse Has Many relation this is getting pushed back. Really love to see this implemented, but I guess I need a bit more time.
Hm, I took a closer look at HasManyBy. It might be enough for me as well. I have a list of objects A with ids and then a list of objects B which each have some number of As, but the As don't care about which Bs are referencing them, so it should work that way. Anyway, I'll stop derailing this issue now. :D
Just FYI - according the the docs @HasManyBy is a decorator - which works only in typescript?
It may be unusual for a project with our level of complexity, but we don't use typescript.
Or is it just that the docs aren't clear on this yet and I could use it without typescript?
@smilingkite you may want to refer to this https://next.vuex-orm.org/guide/relationships/one-to-many.html#one-to-many-by
Any traction on this? I've done some pretty whacky stuff with hasManyBy(), but there's a lot of holes in it that could be solved by bringing back many to many relationships in Vuex ORM.
@kiaking Can you show example of HasManyBy for the inverse relation to "fake" belongsToMany?
I tried this but because the ORM only stores 1 id for each relationship instead of a pivot table, this breaks when models have more than one ManyToMany relationships with eachother.
What is the timeframe for implementing this and morphMany. I am anxious to use these features.
Any update on this? In my opnion this was the best part about vuex-orm.
For instance if you have Channels and Users you have Users.subscribed. The model in the middle UserSubbed can than be used to store a date for instance.
This many to many missing is the only feature currenlty stopping me from upgrading my project.
Ok turns out you don't actually need belongsToMany.
I made this issue on the pinia-orm repo with an example of how to convert a belongsToMany to HasMany.
https://github.com/CodeDredd/pinia-orm/issues/8
I hope this is helpful to everyone!
Well i have a working version of it https://github.com/CodeDredd/pinia-orm/pull/79 for pinia which can easly be added back here. I am happy to make an pr if its being merged.