vuex-orm / vuex-orm-next

The next iteration of Vuex ORM.
https://next.vuex-orm.org
MIT License
189 stars 11 forks source link

Add Belongs To Many relation #36

Open kiaking opened 3 years ago

kiaking commented 3 years ago

Ref: https://vuex-orm.org/guide/model/relationships.html#many-to-many

smilingkite commented 3 years ago

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.

M3psipax commented 3 years ago

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.

kiaking commented 3 years ago

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.

M3psipax commented 3 years ago

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

smilingkite commented 3 years ago

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?

cuebit commented 3 years ago

@smilingkite you may want to refer to this https://next.vuex-orm.org/guide/relationships/one-to-many.html#one-to-many-by

salcedo commented 2 years ago

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.

salcedo commented 2 years ago

@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.

mrvanwagoner commented 2 years ago

What is the timeframe for implementing this and morphMany. I am anxious to use these features.

tintin10q commented 2 years ago

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.

tintin10q commented 2 years ago

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!

CodeDredd commented 2 years ago

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.