Open elfeffe opened 4 years ago
Maybe the Pivot table must be optional. If you have thousands of categories and thousands of documents, you have a problem with the actual behavior. Documents and indexes are huge
@elfeffe is it actual?
@Smolevich Yes, I'm using it with L7 (I think package version was the alpha for L7). The thing is, when you have thousands of relations, you have a field with thousands of IDs. I think a pivot table will do the job, I don't understand why pivot tables are "prohibited". MongoDB accepts a JSON, and that's great, but relations are also good some times.
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. I mean, I'm not using the belongsToMany relation anymore, I'm using a custom solution with a pivot table.
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?