vuex-orm-next icon indicating copy to clipboard operation
vuex-orm-next copied to clipboard

Add Belongs To Many relation

Open kiaking opened this issue 4 years ago • 12 comments

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

kiaking avatar Nov 17 '20 02:11 kiaking

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.

smilingkite avatar Feb 11 '21 09:02 smilingkite

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.

M3psipax avatar Jul 27 '21 17:07 M3psipax

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.

kiaking avatar Jul 27 '21 17:07 kiaking

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

M3psipax avatar Jul 27 '21 17:07 M3psipax

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 avatar Jul 28 '21 14:07 smilingkite

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

cuebit avatar Jul 28 '21 14:07 cuebit

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 avatar Jan 26 '22 20:01 salcedo

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

salcedo avatar Mar 01 '22 15:03 salcedo

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

mrvanwagoner avatar Mar 19 '22 13:03 mrvanwagoner

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 avatar Apr 16 '22 14:04 tintin10q

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!

tintin10q avatar Apr 17 '22 13:04 tintin10q

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.

CodeDredd avatar Jul 12 '22 02:07 CodeDredd