-
Notifications
You must be signed in to change notification settings - Fork 1.5k
there is no need to save the ids in both collections for a belongsToMany relation, or am I wrong? #2040
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
Comments
Maybe the Pivot table must be optional. |
@elfeffe is it actual? |
@Smolevich Yes, I'm using it with L7 (I think package version was the alpha for L7). You can save, in this example, the category Id inside the product, but if the product is related to thousands of categories you will have the same issue. I'm resolving it by myself with a pivot table, search the relation there and then load the products with the IDs from the pivot table, and it's fast, MongoDB indexes are great, but not if you have a field with 15000 ids inside. MongoDB is great because you are not obliged to design a grid, like in MySql, so you use much less tables because you almost don't use relations. But that doesn't mean we can't use relations, they are supported by MongoDB from long time ago. A pivot table ill be a perfect solution. A similar issue is the embedded relation, is totally useless because to load the relations takes micro seconds, it seems like someone said "we use MongoDB, relations are prohibited". Maybe they were, but MongoDB supports it from long time ago. |
@elfeffe you have good points, as an example doctrine odm has a few different strategies to save relation data I can only agree that all this makes sense, however the problem is here that it's almost impossible to do that without a breaking change release. This library was written a long time ago and many things has changed even in Laravel itself, complete rewrite from scratch might solve everything but decisions should be made which isn't easy as it looks. Thanks! |
I'm doing
And this is saving the related ids on both collections, so if I have 1 category, with 10000 products, the category has an array of 10000 products inside.
What's the reason?
Saving the category inside the product will do the job, or I'm losing something?
The text was updated successfully, but these errors were encountered: